OVER THE
■ECTRUM
OVER
THE
SPECTRUM
Melbourne House Publishers
Fublished in the United States of America by:
Melbourne House Software Inc.,
233 South Beverly Drive,
Beverly Hills,
California 90212
Fublished in the United Kingdom by:
Melbourne House (Publishers) Ltd.,
Glebe Cottage, Glebe House,
Station Road, Cheddington,
Leighton Buzzard, Bedfordshire. LIT?, 7NA.
ISBN 0 86161 109 8
Published in Australia by:
Melbourne House (Australia) Pty, Ltd.,
Suite 4, 75 Palmerston Crescent,
South Melbourne, Victoria, 3205.
National Library of Australia Card Number and
ISBN 0 86759 112 9
All progtams in this book are Copyright (c) 1982.
Programs not otherwise Indicated are Copyright (c) 1982 by
Beam Software,
All rights reserved. This book is copyright. No part of this
book may be copied or stored by any means whatsoever whether
mechanical or electronic, except for private or study use as
defined in the Copyright Act. All enquiries should be
addressed to the publishers.
Printed in Hong Kong by Colorcraft Ltd.
PUBLISHER'S NOTE
We at Melbourne House are very excited to be involved
with the publication of this book, making available as it
does not only 30 interesting and varied programs For the
Sinclair ZX Spectrum - undoubtedly the most powerful and most
affordable small computer in the world - but also showing you
how to Use the computer's complete facilities to its maximum.
This book offers you not only strategy, gambling and arcade
games but also utilities, business and educational programs.
We are also publishers of other titles for the
Spectrum computer, as a glance at the back pages of this book
will show, ranging from titles for the complete beginner to
titles of interest to more experienced users.
We have a commitment to providing literature and
software for the Sinclair ZX Spectrum, and as you will note
by leafing through this book, many of the programs we publish
are the result of programs that were submitted to us by ZX
Spectrum owners.
So if you have a program or article you think would be
of interest to other ZX Spectrum owners, please write to us.
We will give you a prompt assessment and reply whether the
material is something we could use.
In the meantime, happy computing.
contents
GENERAL PROGRAMS
Leapfrog... 1
Number Reversal .............4
Asteroids in Space., ,.........7
Spectrum Clock. 10
3-D Mazeman....,15
EDUCATIONAL
Geo metry Test...,,,,,,,,,,,.,21
Kings and Queens,23
GAMBLING GAMES
Blackjack.. 27
Fruit Machine .. 32
MATHEMATICAL
Bubble Sort*. .,41
Simultaneous Equations 47
#
ARCADE GAMES
Space Escape.,.,.51
Lunar Lander...*_*,,,..55
Alien Blitz.........60
Spect rum Invaders. 64
Meteor Storm.69
Eliminator,.. ,77
Freeway Frog,. .83
UTILITIES
High Resolution Graphics...*,.,*»*»*95
Line Renumbering.****.*,,*#.. 102
Block Line Delete**,,.......... 10B
Machine Code Monitor*#.*..Ill
BUSINESS PROGRAMS
Payroll. IIS
Sa1es Ana lysis******..........125
Possessions Evaluation._********130
STRATEGY PROGRAMS
Chess......
Dr augh ts. 141
Adventure152
4
NOTES ON THE PROGRAM LI SUNOS*
As you are no doubt aware, there are a
number of different modes available in
operating the Spectrum keyboard, each
resulting in a different keyword or graphic
symbol being recorded by the Spectrum-
The program listings in this book have been
specially designed and printed to make
reading these listings easier. A few words
may be needed to explain the meaning of some
of the symbols*
*
This symbol is used whenever
a space is to be entered in the
program. This may be in a graphics
character string, or it may be in
a PRINT statement-
Spaces have been used in these
programs to aid readability, and
in some cases are essential to
the proper working of the
program.
SMI
This symbol is used to indicate that
the CAPS SHIFT key needs to be held
down for the next character*
EAX
4
This symbol is used to indicate that
you need to be in EXTENDED mode to
enter the following character.
EXTENDED mode is obtained by pressing
both the CAPS SHIFT and SYMBOL SHIFT
keys together* See your Spectrum
manual for more details.
GRfl
This symbol is used to indicate that
you need to be in GRAPHICS mode to
enter the following character.
GRAPHICS mode is obtained by pressing
the "9 M key while holding down the
CAPS SHIFT key- See your Spectrum
manual for more details.
I NV
Indicates INVERSE VIDEO mode.
Press "4" and CAPS SHIFT keys
together.
TRtJ
Indicates TRUE VIDEO mode.
Press *'3" and CAPS SHIFT keys
together.
Further nates on the use at EXTENDED MODE
In this boot we h^ve made use of all the facilities
of the ZX Spectrum. inlcuding the ability to specify
the paper and ink color from within a program line or
PRINT statement.
This is achieved by entering EXTENDED MODE s and then
pressing the appropriate color key (for paper color)
or the CAPS SHIFT key and the appropriate key (for
ink color).
For example, this is shown in the book as ;
E>■ T SHI 3 (choose ink color 3>
or ext 6 (choose paper color 6*.
To demonstrate this* the following may he] o ;
EXT SH 1 3 : 1* Press both the CAPS SHTPT
and SYMBOL SHIFT keys.
The U K" Cursor should now
have changed to an *'E".
2. Press the CAPS SHIFT key.
while holding thi^ key
press the “3 n key. The
cursor will now be a "K**
again*
Ex r h * 1. Press both the CAPS SHIFT
and SYMBOL SHIFT keys.
The "K* 1 cursor should now
have changed to an <J E”.
2. Press the “6" key*
The cursor will now be a
”J<" again,
Leapfrog
Copyright (c) by Beam Software
The game of leapfrog is a nice simple one:
You start off with two opposing sets of frogs* and each
frog can only move to an adjacent space or leap over one
f rog«
HXX- 0 0 0 0
12 3 4 5 6 7 8 9
So„ as a first move, for example the frog at position 4 can
move to 5, or the frog at 6 can move to 5, or the frog at 3
can leap over the frog at 4 to land at 5, or the frog at 7
can leap over the frog at 6 to land at 5.
The object of the game is to try to get all the frogs on
the left to the right* and vice versa in the least number of
moves, It's great fun!
Structure of the program:
The first part of any program is to Initialise any variables
that might be required. In this case, we want to define the
initial position of the frogs* and set the number of moves
taken so far to zero-
An overview of the program reveals the following structure:
Initialise variables
Print Print position of frogs
Check if finished
If yes* then go to Finish
Input Enter player's move
4 Check if move is allowed
If noL, go to input again
Add one to the number of moves
Make the move and go to Print
Finish Congratulate pLayer
Ask player if he wants to play again
If yes, then RUN again
This simple fl top-down n approach gives us an overview of the
program, and lets us understand the program should we wish to
make any changes at a later stage.
Structure of the variables:
For this program we shall be using "string variables" to
define the position of the frogs, A string variabLe is easy
1
to manipulate in this context, and makes printing very fast.
We define a$ as the original position of the frogs and b$ as
the present position. We can use the same variables to check
If we are finished (see line 150)*
We use the variables "to" and "from" to represent the
position the from is moving to and from. Because a frog can
only move into an empty position we can check this easily
(see line 200),
The rest of the program is very straightforward, with "count"
being the number of moves taken.
Running the program:
The program expects a 2-digit input to define the moves to
and from. It will accept as a valid firsL move only the
following inputs:
35 45 65 75
Happy leapfrogging?
4
2
LEAPFROG
100 LET a$ = " GRA SH I 0, SRfl £HJ 8*
KR A SHI S* GRfl 5 H I 0 ^ ^ ^
aaa am 6^ orb am 6^
GHfl SHI 6* GRfl SHI 6"
110 LET b* = a*
120 LET count = 0
130 CLS
140 PRINT AT 5, 33 b*J AT 6 t 35
“ 1 *2^3^# ^5*6*7 *8^9"
150 IF b*(l TO 7) = a*til TO 17> AND
bPll TO 17) = a* U TO 7> THEN GO TO 250
160 INPUT "Please*enter*your^move”; k%
170 IF LEN k$ 02 THEN GO TO 160
100 LET from = 2*< CODE k*<l)-4B)-l
190 LET to = 2*< CODE kS<2>-48>-!
200 IF b*tto) <> 11 OR ABS tto-from) > 4
THEN GO TO 160
210 LET count = count+1
220 LET b*Cto) = b*(from)
230 LET b* (f ront) - " * M
240 GO TO 140
250 PRINT “You^did^it^in^i count; “ * moves*'
260 INPUT "Another^go?"; k*
270 IF CODE k* = 121 THEN RUN
*
3
Number Reversal
Copyright (c) Beam Software
This is a puzzle to test your powers of logic! You start
with 9 numbers, from 1 to 9, in a random order.
The aim is to get them into order in as few moves as
possible. The only facility you have to change the order of
the numbers is the ability to "reverse 1 ' the order of some of
the elements.
For example, if you had the first three numbers "3 2 1%
then reversing the First three will give you f, l 2 3'*, If you
had reversed only the first two, you would have had "3 1 2",
Note that you can specify only how many numbers you would
like reversed. This program is quite short, so entering it
into your computer will be easy, and it will certainly
challenge your powers of logic.
Programming notes:
This program highlights the use of arrays, and also shows
how easily readable programs can be if you are prepared to
take the trouble to define meaningful variable names*
Look at the program listing - there is no need for a
separate program structure, because all the information you
need is there,
Note also that it is possible to put spaces at the beginning
of lines to make FOR-NEXT loops, etc,, more obviously
high lighted.
Th* use of variable names for line numbers in GOTOs and
GGSUBs is also a very efficient way of keeping track of what
is going on, it also minimises the work that has to be done if
you use the RENUMBERing routines provided later in this book.
Use of arrays:
The use of arrays allows us to easily refer to a particular
element without having to have a separate name for each
element.
At the beginning of the program we dimension the array, and
this sets each member of the array to zero. Note that the size
of the array is defined in a variable, so if you want to test
your logic with a longer list of numbers you can do so by
simply changing that one line*
4
Note the way that the numbers are made to appear in random
order - we take each number in turn and swap it with the
number in a randomly chosen position. This algorithm is also a
very useful and efficient way of shuffling cards in a card
program.
4
5
NUMBER REVERSAL
100 LET print - 600
110 LET reverse = 400
120 LET input = 300
130 LET size = 9
140 DIM a(size)
150 FOR c » 1 TO size
160 LET a(c> - c
170 NEXT c
100 FOR c = size TO 2 STEP -1
190 LET swap - 1+ INT (size* RND >
200 LET temp - a(c>
210 LET ate) = a(swap)
220 LET a(swap) - temp
230 NEXT c
240 LET count = 0
250 GO SUB print
300 INPUT "How^many ^numbers^do^you^wish ^to
*reverse? *"; howmany
310 IF howmany = 0 THEN STOP
320 IF howmany <— size THEN GO TO reverse
330 PRINT size; 11 s^maximum A that*can*be
^swapped' 1
340 GO TO input
400 PRINT "Reversing^* 1 ; howmany 5 “^numbers"
410 LET count = count+1
420 FOR d — 1 TO INT (howmany/2)
430 LET temporary =*= a < d)
440 LET mirror *= howmany—d+1
450 LET a(d) = a(mirror)
460 LET a(mirror) = temporary
470 NEXT d
480 GO SUB print
490 FOR d = I TO size
500 IF aid) <> d THEN GO TO input
510 NEXT d
520 PRINT "You *di d^i t *in , count; " A mave5, 11
530 STOP
600 POKE 23692, 255
610 FOR d = 1 TO size
620 PRINT a (d) ; "* ,J |
630 NEXT d
640 PRINT
650 RETURN
6
Asteroids in Space
Copyright (c) by Neil Streeter
You are travelling through space in your spaceship, when
suddenly you encounter a space storm*
You can steer your ship past the debris only by using your
rudder controls (key 1 V to go left, and key 1 8 t to go right)
- hyperdrive has been disabled by one of the meteors.
As if this was not bad enough, If you do survive the meteor
storm, you will find you have become so disoriented that you
are travelling the wrong way in the space lanes* All the
space traffic is coming directly at you.
You must steer past these in the same way as be fore, but
the space ships are bigger than the meteor debris* so it is
more difficult*
Eventually, you will CRASH! When you do, you will find the
survival rating on the screen of your spaceship console*
Program structure:
This program simulates the use of the SCROLL function,
which is available on most micro computers, but not on the
Spectrum*
You are no doubt familiar with SCROLL already, as for
example the program listing scrolls, but you may have noticed
there is no command directly available to you to achieve the
same result*
The same result can however be obtained by changing the
value of the variable SCR-CT (this is achieved by PGKEIng
23692 # - see Machine Code Monitor notes for more information
about PEEK and POKE), and then printing two spaces at the end
of the screen {ie AT 21,31).
When the display is SCROLLed, your ship will move with
everything else, so it is overwritten with blanks, then
printed again in the correct position. In this way, your ship
stays on the same line in the screen, while everything else
move s *
The asteroid debris and space ships appear randomly on the
bottom of the screen, and the information about their
position is kept in variables a, b, c, d, and e f with e being
the closest. By comparing e with the position of your ship,
the program determines whether you are about to crash.
The screen is SCROLLed two lines in each cycle, so that
there are only II asteroid debris on the screen at any one
?
time. You could SCROLL only once in each cycle* but this
means there would he far too much asteroid debris on the
screen * and you would have to keep track of twice as many
variables.
Improving the program:
The program has been deliberately kept simple to allow you
to improve tt.
The first step that can be done is to use the facilities of
the Spectrum’s user defined graphics to define really
exciting shapes for your ship and for the asteroid debris.
Secondly, you will note that there are two places in the
program where sound is generated through the BEEP command-
The purpose of these commands is not merely to create sound!
Try deleting those lines* and I'm sure you will find the
program runs much too fast for you.
You can therefore speed up or slow down the program by
changing the length of the note or number of notes to be
played.
There is also sufficient time in each cycle for you to
write in additional ships attacking you* adding the ability
for you to fire at the asteroids*, and so on.
4
8
ASTEROIDS IN SPACE
100
LET a* =
no
LET n ~ 0
120
LET a * 0
130
LET b = 0
140
LET c - O
150
LET d — 0
160
LET t = 1
170
LET x ^ 12
ISO
LET r = INT
(27*
RND >
190
PRINT AT 21,
r 3
INK (4* RND >I a*
200
POKE 23692,
255
210
PRINT AT 21,
313
■I it
■*-
220
BEEP * 3, 0
230
PRINT AT lO,
x—2
m ll 11
f *. A A Jfc
240
PRINT AT 11,
x i
" SFm 6 SRft SMI
250
PRINT AT 21,
315
H H
260
LET n = rv+t
270
IF n =* IOO THEN
LET a* - " GRA SMI 6 fiflfl SHI 7”
280 IF n = 104 THEN LET t = 2
290 LET e ^ d
300 LET d - c
310 LET c * b
320 LET b = a
330 LET a = r
340 PRINT AT 10, x~2 3 " * ^ „ * * ■'
350 PRINT AT 11, «3 ° SBfl* 6* fififl 5J±I
360 IF x >= e-2 AND x <= e+t THEN GO TO 410
370 BEEP ,2, 5
380 IF INKEY* = "S" THEN LET x = x-t
390 IF INKEY* = “8" THEN LET x * x+t
400 GO TO 180
410 PRINT AT 11, M-ii “CRASH 1 '
420 PRINT AT O, OS "SCORE * "i n
430 BEEP 2, -12
440 PRINT AT 21, 03 "Press ^any * key *to^try
*again"
450 IF INKEY* = ,,,, THEN GO TO 450
460 RUN
9
Spectrum Clock
Copyright (c) Beam Software
DESCRIPTION
This program is a simulation of a REAL-TIME CLOCK;
both normal clock and digital clock are implemented and
displayed on the screen. You will be amazed at the
accuracy of the SPECTRUM CLOCK; not only that, you can
also set the ALARM and the SPECTRUM CLOCK will remind you
by generating alarm tone.
HOW TO RUN THE PROGRAM
Type RUN followed by (ENTER) to start the program*
You will need to enter the HOUR, MINUTE, SECOND which
you want the clock to start* Note that HOUR is entered in
a 24 hour basis; it means that you have to type in 13th
hour instead of l PM,
The program checks the validity of the input, so you
can't type a negative number or any number greater than
60 for minutes and seconds; they won't be accepted.
You will have to input in a similar way if you want
to set the alarm.
One method of using this alarm effectively is as an
EARLY MORNING ALARM : Run the program at night, setting
the correct time and the alarm, then turn the TV off to
save electricity.
The SPECTRUM will continue running the program until the
alarm time is reached, and the sound of the internal
beeper may wake you up.
PRQC^M STRUCTURE
The program uses the SPECTRUM frame-counter as its
internal clock* The frame-counter is stored in three
bytes starting at memory Location 23672 with least
significant bytes first. Every 20 ms, the frame-counter
is increased by 1; in other word, the total of counter
divided by fifty will give the number of seconds from
start of count.
The structure of the program is as follow :
INITIALISATION
INPUT HOUR MINUTE and SECOND
IF SET-ALARM
INPUT ALARM HOUR MINUTE and SECOND
DISPLAY ALARM TIME
10
DRAW CLOCK RACE
CALCULATES INITIAL VALUE OF FRAME COUNTER BYTES
POKE VALUE INTO FRAME COUNTER WHEN ANY KEY PRESSED
DEFINE FUNCTION : no, of seconds since start
INITIALISE STARTING TIME
MAIN LOOP
H: DETERMINE HOUR HAND POSITION
M: DETERMINE MINUTE HAND POSITION
S: DETERMINE SECOND HAND POSITION
DRAW SECOND HAND
DRAW MINUTE HAND
DRAW HOUR HAND
CALCULATE AND DISPLAY DIGITAL CLOCK
determine hoqr minute second digits
adjust lor cross noon boundary
IF ALARM TIME MATCHES WITH DIGITS
FLASH CLOCK and GENERATE ALARM
FETCH FRAME COUNTER UNTIL ONE SECOND HAS PASSED
DRAW OVER SECOND HAND
IF SAME MINUTE THEN GO TO S;
DRAW OVER MINUTE HAND
IF SAME HOUR THEN GO TO M:
DRAW OVER HOUR HAND
GO TO H:
SPECIAL FEATURES
DEF FN t{) is used to facilitate frequent
referencing of FRAME COUNTER.
SIN and COS functions are used to draw clock hands*
SECOND hand is moved every second; MINUTE hand is
moved every minute; HOUR hand is moved every 12 minutes.
Program takes care of AM/PM setting.
Checking is built into the program to ensure validity
of time input,
SPECIAL NOTES
The SPECTRUM CLOCK is accurate up to 10 seconds
deviation per day provided that the computer is only
running this program without generating any LNPUT/OUTPUT
including sound. Note that the frame counter is no
longer an accurate clock once any input/output is
performed because the frame counter is not incremented
during that time.
Once Alarm is reached, the clock will need to be
reset; that is* if you want to use the clock again you
will need to RUN the program again *
11
SPECTRUM CLOCK
lOO GO SUB 360
110 LET c = PI /30
120 DEF FN tO = INT < (65536* PEEK 23674+256*
PEEK 23673+ PEEK 23672)/50>
* REM no ^ ^second ^5inee ^start
130
REM
Now,*
we^start^the^cl ock
140
LET
tl =
FN t()
150
LET
hi =
INT Ct 1/720)
160
LET
h =
hi *c
170
LET
hx -
50* SIN h s LET
hy = 50*
COS
h
180
LET
mi =
INT < 11/60)
190
LET
m =
mi #c
200
LET
mx =
60* SIN m * LET
my = 60*
cos
m
210
LET
a =
tl*c
REM
angle t Df^second ^hand
ln*radian
220
LET
sx =
: 72* SIN a s LET
sy = 72*
cos
a
230 PLOT 131, 91 s DRAW sy
* REM DrattiSecondihand
240 PLOT 131, 91 ? DRAW m* < my
250 PLOT 131, 91 £ DRAW hx, hv
260 GO SUB 740
270 LET t = FN tO
280 IF t <= tt THEN GO TO 270
* REM wai t *unt i1 A time *nex t *hand
290 LET tl 5= t
300 PLOT 131, 91 ; DRAW OVER l; sx , sy
- REM ^er^se^Beconci^hsnd
310 IF INT (t 1/601 <= ifti THEN GO TO 210
320 PLOT 131, 93 = DRAW mx, mv s PLO* 133. 91
* DRAW OVER 1 ; ffiX , fnv
330 IF INT (t1/720) <= hi THEN GO TO ISO
340 PLOT 131, 91 - DRAW hx, hy = PLOT 131, 91
s DRAW OVER l; hx , hy
350 GO TO ISO
360 £iU 3±U O BORDER 7 i PAPER 7 i INK O s OVER 0
* i FLASH O * CLS
i PRINT "FleasGiinput.which,hDur 7 "
* PRINT *■ <0*-*235 lf
370 INPUT H* IF H < O OR H > 23 THEN GO TO 370
380 PRINT FLASH 1; INK 2s H
390 LET D = 0 i If H >= 12 THEN LET D = 1
s LET H = H—12 * < H < > 12)
400 PRINT '‘Which * MINUTE' 5 " * PRINT M (G*-*59>"
410 INPUT Mi IF M O PR h > 59 THEN GO TO 410
420 PRINT FLASH 1; INK i; M
430 PRINT "Which *SECOND? 1 ' ± PRINT H <G*-59) “
440 INPUT S s IF S3 0 OR S > 59 THEN 60 TO 440
450 PRINT FLASH 1; INK 35 S
460 PAUSE 50 * CLS
470 PRINT "Do*you*wantset *the *ALARM*?"
i PRINT "(y^or.n) 1 '
480 INPUT at
i IF at <> "v f - AND at <> tJ n" THEN GO TO 480
12
CLS
490 If a* = ,f n 11 THEN LET al = 0
s BOEDER D i PAPER O - INK 7 *
± GO TO 630
500 LET £1*1* PRINT s PRINT "Hour7 *" ;
510 INR'UT ah i If ah < 0 OR ah > 24 THEN GO TO 510
520 PRINT ah t LET ad = O
? IF ah >11 THEN t_ET ad ^ 1
* LET ah = ah— tah <> 12)*12
530 PRINT * PRINT "Minutes?*";
540 INPUT am
? IF am < 0 OR am > 59 THEN GO 10 540
550 PRINT am
560 PRINT ; PRINT "Second? * fi ;
570 INPUT as
s IF as \ 0 OR as > 59 THEN GO TO 570
580 PRINT as - PAUSE 50
590 REM Draw^clotk*fcice
600 PAPER 0 s £>:T S H I 0 BORDER 0 - INK 7 * CLS
i PRINT AT 20, 0; 11 ALARM 1 '
s PRINT ah; J ' * " ; am; " *"5 as; U * H S
610 IF ad = 0 THEN PRINT "AH" * GO TO 630
620 IF ad = 1 THEN PRINT "PH"
630 FOR n — 1 Tu 12
640 PRINT AT 10-10* COS m/6* PI >
* lo+lO* SIN (n/6* PI K n
650 NEXT n
660 LEI dh = H * LET dm = M * LET Os = S
670 LET T = (H*36QO+M*60+S>*50
680 LET bl = T- IN T vT7256)*256
&9G LET b2 - INT (T/256>- INT (T/256 A 2)*256
700 LET b > = INT tT/256 2>- INT (T/256 3)*256
71 ( IF INKEY* = 11 " THEN BC< TO 710
7.M POKE 236/4, D3 s POKE 23673, b2
- POKE 23672, bl
730 RETURN
740 LET ds = tl- INT (t1/60)*60
: LET dm = INI INT (t1/3600)*60
- LET dh = INT tt1/3600I
750 IF ds — O THEN PRINT AT 6. O?
760 IF dh >= 13 THEN LET dh = dh-12
770 IF dh <> 12 OR ds <> O OR dm <> O
THEN GO TO 810
730 IF D =* O THEN LET D = 1 * LET dh = 12
‘ GO TO 810
79 i IF D = 1 THEN LET D = 0 * LET dh = 0
300 LET dh - dh-<dh = 12 AND D = 0)*12
81 i PRINT AT 0, 03 dh; .; dm; " t "; FLASH 1
; ds
8?0 PRINT AT O, 8; 11 *";
830 IF D = O THEN PRINT '/AM"
840 If D = 1 THEN PRINT "PM"
050 IF al = O THEN RETURN
860 IF ah w dh OR am \ > dm OR as x > Os OR ad <. > D
THEN RETURN
670 ^rint AT 0, 0 3 dh; " S *' f dm* " - “; ds
13
; FOh s = 22523 TO 2-3231
i POKE 128+ PEEK s ±
BSC BEEP 0.5. 27 - BtE- 0,5* 2
- IF INKEV* = ■*" FHEN bD
B90 RETURN
NEXT s
70 870
14
3-D Mazeman
Copyright (c) by Beam Software
You are trapped in a maze. You must get out! The pressure
is getting to you.
You move forward, a doorway appears on the left, quick!
Oh no* . ■ . another dead end!
Will you ever get out of here alive?
This amazing 3-dimensional simulation places you right in
the maze* with the task of getting out. The only thing to be
thankful for is that there are no monsters here!! Yet!!
You can take as long as you like* but the time you take is
being measured. At each position you will see a realistic
perspective view. You can turn left or right (using the f V
and ,r p' T keys respectively)* move forward (using the space
bar) or turn around (using the u r" key).
If you get really lost* it might be a good idea to draw a
map.
Program structure:
This program uses the PLOT and DRAW functions of the
Spectrum.
At each point down the corridor, there is the option of the
doorway being open or the doorway being closed* This program
uses a different subroutine to draw the doorway depending on
its distance from the observer and depending on whether it’s
open or not,
Thi# explains all the different subroutines from 6000 to
8 SOB.
A separate data table (lines 9100 - 9200) defines the
particular maze you are in*
Defining your own maze:
The maze used here is drawn on a 9 x 9 grid* somewhat like a
Chess board* and each position in the maze is represented by
a square on the board.
Obviously each square can have walls in any of the four
directions. This program uses two arrays to keep track of
walls* one array for the walls found looking up the board*
and one array looking across.
15
A total of 18 lines need to be defined, 9 looking up at the
board, and 9 looking across. For each line, we put a 0 down
if there is no wall blocking our path, and a 1 if there is a
wall there. There are always walls on the outside perimeter,
and these do not need ot be defined.
This information is stored Ln the DATA statements 9100 -
9108 and 9200 - 9208.
For example, looking up the board from the bottom left
corner, we see a wall. If we were able to break through that
wall, there would be another one, and the another. Finally we
would see a corridor stretching four squares before the last
wall. This is the information contained in line 9100.
The exit Is defined by line 156. It says that if you are in
the 9th row, and facing backwards, and less than 5 from the
end you will see the EXIT sign. The requirement of 5 from the
end is because there is a wall in the current maze blocking
the view if you are say 6 from the end.
You can easily adapt the program to show your own maze, but
remember to change the conditions for EXIT,
16
3-D MAZEMAN
10O DIM v (10, 10> i DIM h(10, 10>
110 60 SUB 9000
120 LET x = 1 * LET y - 1 s LET dxi * 1 a
LET dy = O
125 LET tl = PEEK 23672+256* PEEK 23673+4096*
PEEK 23674
130 LET L = 9 t LET Lx - x + (dx = -1> *
LET Ly = y+(dy = -1 }
132 LET L = L-l * LET Lx « Lx+dx * LET Ly = Ly+dy
134 IF dx <> O AND v(Lx, Ly) = O THEN GO TO 132
136 IF dy <> 0 AND hlLx, Ly) = O THEN GO TD 132
140 CLS * 60 SUB 6000+L
145 LET Lx = Lx-(dx = -1) ± LET Ly = Ly-<dy = “1>
ISO FOR i = L TO 8
155 LET Lx = Lx-dx * LET Ly = Ly-dy * GO SUB lOOO
i NEXT 1
156 IF dx = -I AND y - 9 AND x < 5 THEN PRINT
AT 10, 14! " LX T 5JtU 2EXIT
F.XT SH 1 O"
158 LET a* = INKEY* * IF 3f - "" THEN 60 TO 158
160 IF a* <> THEN 60 TO 190
170 IF (dx = 1 AND v(x+l, y> = 0) OR
{dx “ -1 AND v (x, y) » 0> OR
(dy = 1 AND h(K, y+1) = 0) OR
<dy = -1 AND h <x t y) = 0> THEN
LET x = x+dx t LET y = y+dy
190 IF x - 1 AND y =9 THEN GO TO 9990
200 IF a* * “r “ THEN LET dx = -dx $ LET dy = -dy
- GO TO 130
210 IF ai = *'o" THEN GO TO 300
215 IF a* <> "p" THEN GO TO 130
220 IF AB5 dx = 1 THEN LET dy - -dx * LET dx = O
s GO TO 130
230 LET dx = dy s LET dy = O t GO TO 130
300 IF ABS dx = 1 THEN LET dy = dx * LET dx * 0
t GO TO 130
310 LET dx = -dy * LET dy - 0 * GO TO 130
lOOO IF dx <> 1 THEN GO TO 1100
lOIO IF h(Lx f Ly+1> » O THEN GO SUB 7500+1
; GO TO 1050
1020 GO SUB 7000+1
1050 IF h < Lx, Ly > = O THEN GO TO 05OO+i
1060 GO TO SOOO+i
llOO IF dx <> -1 THEN GO TO 1200
1110 IF h(Lx 3 Ly) = O THEN GO SUB 7500+1 * GO TO 1150
1120 GO SUB 7000+i
1150 IF h(Lxj Ly+1) = O THEN GO TO 0500+i
1160 GO TO 8000+i
1200 IF dy <> -1 THEN GO TO 1300
1210 IF v (Lx+I, Ly) - O THEN GO SUB 7500+1
s GO TO 1250
1220 GO SUB 7000+1
1250 IF v(Lx, Ly) = O THEN GO TO BSOO+i
17
% 1260 GO TO SOOO+i
1300 IF v (Lx, Ly) - O THEN 60 SUB 7500+i
s GO TO 1350
1310 GO SUB 7000+1
1350 IF v(L*+l, Ly) = O THEN GO TO 8500+1
13*0 GO TO 8000+1
6000 PLOT 1lO, 76 : DRAW O, 24 * DRAW 36, O
; DRAW O t -24 i DRAW -36, O * RETURN
6001 PLOT 108, 75 * DRAW O, 26 * DRAW 40, O
i DRAW 0, -26 * DRAW -40, O * RETURN
6002 PLOT 106, 74 - DRAW O, 28 t DRAW 44, O
- DRAW O, -28 i DRAW -44, O * RETURN
6003 PLOT 102, 71 * DRAW O, 34 : DRAW 52, O
i DRAW O. -34 i DRAW -52, 0 s RETURN
6004 PLOT 94* 65 * DRAW O, 46 * DRAW 68, 0
- DRAW O, -46 i DRAW -68, O * RETURN
6005 PLOT 02 * 57 - DRAW 0, 62 * DRAW 92, 0
s DRAW O, -62 s DRAW -92, O : RETURN
6006 PLOT 64, 45 s DRAW 0, 86 * DRAW 120, O
s DRAW O f -86 ; DRAW -128, O * RETURN
6007 PLOT 40, 29 - DRAW O, 1!8 = DRAW 176, O
s DRAW 0, “118 - DRAW -176, O a RETURN
6008 PLOT 8, 7 i DRAW O, 162 : DRAW 240, O
i DRAW O, -162 s DRAW -240, 0 * RETURN
7000 PLOT 108, 75 * DRAW 2, 1 4 DRAW O, 24
t DRAW -2,1: RETURN
7001 PLOT 106, 74 * DRAW ?, 1 : DRAW O, 26
* DRAW -2, 1 : RETURN
7002 PLOT 102, 71 : DRAW 4, 3 : DRAW O, 28
: DRAW -4, 3 : RETURN
7003 PLOT 94, 65 * DRAW B, 6 - DRAW O, 34
: DRAW -8, 6 : RETURN
7004 PLOT 82, 57 : DRAW 12, 8 a DRAW O f 46
= DRAW -12, 8 : RETURN
7005 PLOT 64, 45 s DRAW 10, 12 s DRAW 0, 62
s DRAW -18, 12 * RETURN
7006 PLOT 40, 29 a DRAW 24, 16 * DRAW O, 86
s DRAW “24, 16 : RETURN
7007 PLOT 8, 7 ± DRAW 32, 22 * DRAW 0, 118
: DRAW -32, 22 * RETURN
7008 PLOT O, 1. c DRAW 8, 6 - DRAW O, 162
a DRAW -8, 6 i RETURN
7500 PLOT 108, 76 : DRAW 2, O s DRAW O, 24
: DRAW —2, O = RETURN
7501 PLOT 106, 75 s DRAW 2, O s DRAW O, 26
: DRAW -2, O » RETURN
7502 PLOT 102, 74 a DRAW 4, O a DRAW O, 28
; DRAW -4, O i RETURN
7503 PLOT 94, 71 : DRAW 8, O * DRAW O, 34
s DRAW -6, O : RETURN
7504 PLOT 82, 65 = DRAW 12, O a DRAW O, 46
: DRAW -12, O : RETURN
7505 PLOT 64 , 57 : DRAW 18, O : DRAW O, 62
: DRAW -18, O a RETURN
7506 PLOT 40, 45 : DRAW 24, O = DRAW O, 86
: DRAW -24, 0 2 RETURN
18
7507
7 SOB
BOOO
BOO i
8002
8003
8004
BOOS
BO06
8007
8008
8500
8501
8502
8503
8504
8505
8506
8507
8508
9000
9010
9020
9100
9101
9102
9103
9104
9105
9106
9107
«U0B
PLOT
9, 29 =
DRAW 32, O
± DRAW 0,
118
DRAW
-32
, 0 t RETURN
PLOT
0, 7
* DRAW 8, 0 *
DRAW
1 O, 162
t
DRAW
-0,
O * RETURN
PLOT
148,
75
* DRAW -2,
t s
DRAW
O, 24
DRAW
2,
1 s RETURN
PLOT
150,
74
s DRAW -2,
1 i
DRAW
0, 26
;
DRAW
2,
1 = RETURN
PLOT
154,
71
i DRAW -4,
3 5
DRAW
O, 28
s
DRAW
3 - RETURN
PLOT
162,
65
; DRAW -B,
6 s
DRAW
0, 34
;
DRAW
0,
6 * RETURN
PLOT
174,
57
t DRAW -12,
0 *
DRAW O, 46
;
DRAW
12,
0 * RETURN
PLOT
192,
45
i DRAW -18,
12
- DRAW O, 62
t
DRAW
10 ,
12 ± RETURN
PLOT
216,
29
* DRAW -24,
16
s DRAW 0, B6
DRAW
24,
16 i RETURN
PLOT
248,
7 =
DRAW -32,
22 i
DRAW 0, 1 18
t DRAW 32, 22 s RETURN
PLOT 255, 1 ; DRAW -8, 6 * DRAW O, 162
* DRAW 8, 6 s RETURN
PLOT 149* 76 ? DRAW -2, O = DRAW O, 24
s DRAW 2, O t RETURN
PLOT 150, 75 s DRAW -2 * O * DRAW O, 26
? DRAW 2,0- RETURN
PLOT 154. 74 i DRAW -4, O * DRAW 0, 28
s DRAW 4, O ? RETURN
PLOT 162, 71 * DRAW -8, O ± DRAW O, 34
i DRAW 8, O ± RETURN
PLOT 174, 65 s DRAW -12, O * DRAW O, 46
- DRAW 12. O * RETURN
PLOT 192, 57 s DRAW -18, O s DRAW O, 62
s DRAW 10, O - RETURN
PLOT 216, 45 : DRAW -24, O t DRAW 0, 06
s DRAW 24, 0 * RETURN
PLOT 240, 29 i DRAW -32, O * DRAW O, 118
* DRAW 32, O i RETURN
PLOT 255, 7 ± DRAW -7, O t DRAW 0, 162
DRAW 7,
0 i
RETURN
FOR i
=
1 TO
9 *
LET Mi,
1)
- 1 i
LET
Mi, 10>
= 1
s FOR
i
— 2 TO
9 s
READ a
LET
h<i , j
) =
a
i NEXT
i
s NEXT
i
FOR i
=
i TO’
9 ;
LET v(1,
i)
= 1 =
LET
v (10,
l J =
* 1
- FOR
j
- 2 TO
9 s
READ a
LET
v(j, i» =
a
- NEXT
j
s NEXT
1
RETURN
DATA
1,
1, 1,
0*
0,
O, 0,
1
DATA
U.
0, 1,
0*
0,
1. u.
1
DATA
1,
1, 0,
0,
Op
O, 1,
1
DATA
0.
0, 1,
ip
0,
0, 1,
0
DATA
1,
1* u
0,
0,
t, 1,
0
DATA
1,
O
O
0,
Op
Op 0,
1
DATA
U
li It
Op
Ip
0, 0,
1
DATA
u
1, K
0,
0,
1, 1,
0
DATA
u
o
o
Op
Op
0, Op
0
19
9200
DATA
o.
o s
0,
o P
o ?
Op
Op
0
9201
DATA
U
It
U
1,
o,
It
Op
0
9202
DATA
o,
o.
o.
o 3
0,
0,
Op
1
9203
DATA
0,
1,
o ?
0,
1,
Op
Op
0
9204
DATA
1,
i.
o,
li
it
it
1
9205
DATA
1 ,
U
U
it
It
o.
1
7206
DATA
o,
Of
o.
Op
0,
0,
It
o
9207
DATA
If
0,
o.
it
It
Op
o
7208
DATA
o.
O,
o.
u
Op
Op
o,
1
9990
LET te
= PEEK
23672+256* PEEK 23673+4096*
PEEK
23674
9991
LET t
te
-ti
9992
PRINT AT O
t 4
5 n
WELL *DONE
( 1 a You *got A out 14
9993
PRINT AT 1
* 4
- ii
*
in *
ti *
f
t / 50; + seconds 1 '
9994
STOP
#
20
Geometry Test
Copyright (c) by Beam Software
The particular test questions included in this program
happen to be those of geometry, but the program design is
more general than that.
This program can be used in any situation where a multiple
quest ion/answer series is desired.
One very interesting facet of the Spectrum in a
mathematical test is that either a number answer or a formula
answer can be given. In other words to the question "What is
the area of a circle radius 27'% either the answer "d * PI M
or the answer " 12.75 T ' would be acceptable. (The latter
answer although not exactly correct would be accepted, as
this program accepts as correct replies within ,5 of the
correct answer).
Program structure:
A short control loop from lines 100 — 260 chooses the
question, compares the answer given with that it expects and
prints the appropriate message.
Each question is contained within a subroutine that not
only prints the question but specifics the answer it will
accept,
Ohviously the number and range of questions is limited only
by your imagination.
21
GEOMETRY TEST
too cus
110 LET q = 1+ INT (4* RND )
120 LET m = 2+ 1NT (20* RND >
130 GD SUB qilOOO
200 INPUT r i PRINT r
210 IF ABS (r-a> > .5 THEN BO TO 240
220 PRINT "YES, *the*answer i 5* M i a
230 GO TO 250
240 PRINT "SORRY, i the.answer i was* ,, i a
250 INPUT "Press. < ENTER > .when.ready"3 y*
260 RUN
lOOO PRINT "What.is.the.circum^erence.Df.a
..circle.with.radius* 1 *! m
1010 LET a = 2t PI *m
1020 RETURN
2000 PRINT "What s.the.area.o+.a^circ1e
****wilh.radius. ,J } m
2010 LET a = PI *m*m
2020 RETURN
3000 PRINT “What .i s .the .surface .area .a^ .a
...sphere*with.radius."; m
3010 LET a = (4/3>f PI *m*m
3020 RETURN
4000 PRINT "What.is.the.volume.Df .a.sphere
i*with.radius."i m
4010 LET a *= PI fmlmfm/3
4020 RETURN
4
22
Kings and Queens
Copyright (c) by Beam Software
This program uses a multiple choice format to test your
knowledge of English history.
The computer chooses a year from 1066 to 1461, and asks
you who was reigning in that particular year. Vou will be
given a choice of three names. If the year given is one
where there was a changeover, the correct answer is the
monarch reigning at the beginning of that year* Type in
the answer - only the computer knows for sure if you're
right or not*
At the end of 25 questions, you will be given your result
as a percentage* Since the probability of getting the
right answer by just guessing randomly is l in 3, you
would need to work pretty hard to get less than 30%I
Program structure:
The structure of this program is pretty simple, but what
makes it interesting is the way in which the information
about the monarchs is stored in the program*
As there is only one right answer for any given year
(because of the way we have framed the question), this
program uses the special ability of Spectrum subroutine
calls to be specified by a variable and for subroutine
calls to Eall through to the next line number that
actual ly exi sts *
Look at the program listing - you will see that, tor
example there are no line numbers between 1088 and 1100.
If you entered the instruction 00SUB 1090, the computer
would go to line 1090, find it wasn't there, try 1091,
and sj on, until it finally reached Line 1100, Tn other
words, any number from 1089 to 1100 will come back with
the result
aS - Will lam 2
This is a pretty good start, as William 2 reigned from
1087 to 1100, and as for the purposes of th ; s test, any
year from 1088 to It00 would be accepted as correct.
Let's look at what happens if we were to enter GQSUB
1088:
the program would come back with no particular
information about a$ as all it would encounter would be
the RETURN instruction*
We can take care of this as, for example, this program
does in line 530, by saying that if we get no answer, go
to the subroutine on the next highest line! Ic, if 1088
23
gives you no answer, try 1089, which will return William
2 *
This means that all number within the range of this test
will return the correct answer.
The same program structure can be used for any other test
where a range of non-overlapping values is correct in
different situations.
Kings and Queens of England Part 1:
1066 *
1087
William 1
Norman
1087 -
1100
William 2
1100 -
1135
Henry l
1135 -
1154
Stephen
1154 -
1189
Henry 2
Plantagane t
1189 *
1199
Richard 1
1199 -
1216
John
1216 -
1272
Henry 3
1272 -
1307
Edward 1
1307 -
1327
Edward 2
1327 -
1377
Edward 3
1377 -
1399
Richard 2
1399 -
1413
Henry 4
Lancaster
1413 -
1422
Henry 5
1422 -
1461
Henry 6
#
24
High Resolution
Graphics
Spectrum Clock
Spectrum Invaders
scor* 5J5
huli IM
/Tk /^\ dii /ts
P»J [*! r*J “ m
fS? fS £) jp ^ £?
/!\ ffli /T\ /TV ffl
r+5 r*i r*l r*s r*i
S** ^
y™y y y ^ y™y y”y
ictri XM
* * * »
Freeway Frog
KINGS AND QUEENS OF ENGLAND
lOO DIN p(3>
110 RANDOMIZE
J20 LET 5=0
130 FOR i = 1 TO 25
140 GO SUB 500
150 LET c* = a*
160 GO SUB 500
170 LET b* * a*
10O IF bS = c* THEN GO TO 160
190 GO SUB 500
200 IF a* = b* OR a* = c* THEN GO TO 190
210 PRINT i; ", 4 Who A was*monarch*in*"i *ni
220 LET p(I> = INT <3* RND ) + l
230 LET p < 2> = INT (3* RND 1 + 1
240 IF p(2) ^ pill THEN GO TO 230
250 LET p 13) = 6-p<l>-p<2>
260 FOR t = 1 TO 3
270 PRINT AT 5+t, 5; t! ".**■ 5
280 IF t = p(l) THEN PRINT a*
290 IF t = p(2> THEN PRINT b*
300 IF t = p<3) THEN PRINT ct
310 NEXT t
320 PRINT AT 12, Oj
330 LET x$ ^ * INKEY* * IF < "1" OR x* > ,, 3"
THEN GO TO 330
340 IF VAL x* = p<t> THEN PRINT "GREAT 1 * s
LET s = s+1 s BEEP ,5, 2 i BEEP -2, 5 s
BEEP .2, 7 * GO TO 370
350 PRINT “NO*-*i t*was*"f. a*
360 FDR j = 1 TO 8 * BEEP RND /4* 104 RND -30 ‘
NEXT j s BEEP 1 , -25
370 PRINT FLASH l; AT 20, OS "Press*any^keyor
^the^next*one“
INKEY*
THEN GO TO 380
380 LET x* =
390 IF x* *=
400 CLS
410 NEXT i
420 PRINT "YOU *SCORED 4 "i
430 STOP
500 LET n = INT (3964 RND >+1066
510 LET a* *
520 GO SUB n
530 IF a* = THEN GO SUB n + 1
540 RETURN
1007 LET a*
lOSS RETURN
1100 LET a*
1101 RETURN
1135 LET a*
1136 RETURN
1154 LET a*
1155 RETURN
44s i "^PERCENT"
**= "William*!"
= ‘’William *2"
* "Henry*1"
= "Stephen"
25
1189 LET at
1190 RETURN
1199 LET a*
1200 RETURN
1216 LET at
1217 RETURN
1272 LET a*
1273 RETURN
1307 LET a*
1300 RETURN
1327 LET at
1320 RETURN
1377 LET a*
1370 RETURN
1399 LET at
1400 RETURN
1413 LET at
1414 RETURN
1422 LET at
1423 RETURN
.1461 LET at
1462 RETURN
" Henry JZ '*
"Richard^1
"John"
"Henry^3"
"Edward^l”
"Edward *2"
"Edward ^3*'
“Richard *2
"Henry^4"
"Henry A 5"
"Henryk"
Blackjack
Copyright (c) by Beam Software
This is the traditional casino game at the Club ZX
Spectrum, Welcome! As a special greeting to all our
guests, we will give you a voucher for $100 valid only at
our blackjack tables.
Step right up. The rules of the house are:
- before any cards are dealt you must decide how
much you are prepared to bet# Note that the
Club ZX Spectrum does not extend credit,
- the dealer deals himself one card face up, then
deals you one card face up. You can then choose
as many additional cards as you desire*
- if you have not gone bust (that is, your total
has not exceeded 21) then the dealer will deal
himself additional cards. The dealer always draws
on 16 or below, always sits on 17 and above*
l£ you should win a hand, you win the amount you have
bet. If you and the dealer have the same total, the
dealer wins. Five cards under 21 will win for you
provided the dealer does not have blackjack. If you have
BLACKJACK (a total of 21 in only two cards) then you will
win twice the amount bet, again provided the dealer does
not have blackjack himself.
Step right up ladies and gentlemen*
Structure of the program:
The structure of the program is as follows:
NEW BET INPUT PLAYER'S BET
IF NO MONEY LEFT, STOP
DEAL FIRST CARD TO DEALER AND PLAYER
FOR PLAYER AND DEALER
IF PLAYER ASK IF CARD WANTED
IF NOT SWITCH TO DEALER
DEAL THE CARD AND PRINT IT
CALCULATE VALUE OF HAND AND PRINT IT
IF OVER 21 GO TO PAYOUT
IF DEALER AND OVER 16 GO TO PAYOUT
PAYOUT IF PLAYER BUST, OR IF DEALER TOTAL
GREATER THAN OR EQUAL TO PLAYER
THEN MONEY WON = 0
IF BLACKJACK THEN MONEY WON DOUBLED
KITTY - KITTY + MONEY WON
GO TO NEW BET AGAIN
27
The structure of this program is therefore fairly simple,
and you should have 1 itle trouble changing the program if
you wished to change the ’house rules'.
Graphics displayt
The subroutine at line SOOO defines a one character
design for the four card suits. This subroutine obviously
is only called once at the beginning of the program.
Each card is printed by the subroutine at line 8500. The
card outline, which is light blue, is printed first, and
then the one character suit is printed in the appropriate
colour (black or red).
The problem of how to print the cards themselves then
comes up. As you know there are only 21 graphics
characters easily accessible for use. We have already
used up 4 of them for the suits, leaving only 17.
There are 13 cards possible, but using only a one
character display would make this only as big as the
normal printed characters themselves. The solution
employed in this program is to look up the standard shape
of each character in the ROM where its shape is stored,
blow it up to double size (that is two characters wide,
and two characters high), and store this in the special
graphics character set, as ABCD. Because there is no
standard character for '10' a one—character version of
this is defined in subroutine &0Q0.
This method is a little slow, but in the program itself
this is acceptable as it adds to the mounting tension of
discovering what card has been dealt.
As yom are no doubt aware each character is displayed on
the Spectrum screen as a collection of 8 bytes, and the
definition for the standard character set is stored in
the ROM starting at location 15616. The starting address
of each character can be determined from its code by the
formula 15360 + 8 * code of character (see Line 9020).
The program then has to work to determine how to blow
this up to twice the size, and stores it in the UDG area.
Special notes:
You will notice, a strange notation in line 270
LET a = p(i) - 11
28
In this program the variable 'a' is being used to keep
track of the number of aces in the hand. What this Line
says is
LET a = 0
IF p{i) = 11 THEN LET a = 1
where p(i) is the card total for player i,
The expression could have been written as just above, or
we could have written as
LET a = { pU) = 1 1 )
because we know that on the EX Spectrum an expression
will be set equal to 0 if it is false and equal to 1 if
it is true. As it turns out we can leave out the bracket
without any possibility of error, and so we have the
strange but very compact expression found in line 270-
The other expression that you might find odd is in line
530, where the value of p(i) is calculated. We have just
chosen a card number from 2 to 14, represented by
variable *c', and we want to add the value of c if it
less than or equal to 10 (ie a number card), add 10 if c
is a suit card (12, 13 or 14) and add 1 or 11 if it is an
ace ( c=ll ).
We could do it as
IF c =( 10 THEN ...
IF c ) 11 THEN ...
IF c = 11 THEN ...
but that one line does it almost all* What it says is add
the value of the card if the value is less than 12, and
add 10 if the value is over 11. Simple, isn T t it!
Lines 540 - 560 take care of the ace being counted as 11
or 1, greatly simplifying the program*
Totai= 13
SPECTRUM CRROS
Total=
29
BLACKJACK
100 BORDER 7 * PARER 7 * INK O * OVER O s CLS
1IO LET b* - ,, N23456707TAJQK"
120 LET a = 0 s LET m = 100
130 GO SUB 8000
140 DIM p(4)
150 IF m - O THEN PRINT AT 10, l; "Kitty^stands
! AT 19* 1? "Sory, ^your^cr@d x t
*ha5 *run * out. * *Come * agai n en A you
ihaveifliDre^iifflDney." - STOP
160 PRINT AT 10, 15 "Ki tty ^tands^at **" i m -
PRINT " How * much A do*you *want *to
170 INPUT b
lBO CLS
190 IF b > m THEN GO TO 160
200 LET m = m-b
210 PRINT INK 01 AT Q, 0 5 " YOUR * CARDS" ; AT 11* O;
11 SPECTRUM CARDS"
220 PRINT AT 9, 1; "Total = AT 20, li "Total - "
230 FOR l = 2 TO 1 STEP -1
240 GO SUB 500
250 NEXT l
260 FOR i = 1 TO 2
270 LET a = p<i) = 31
2BO IF \ = 1 THEN INPUT FLASH 1? PAPER 2; INK 7?
"Do A you*want *another i Gard ? *"; at *
LET at *= S IF a*<l> = "n" THEN
BO TO 340
290 GO SUB 500
300 IF p(i) >21 THEN LET i = 2 * GO TO 340
310 IF p (i+2) - 5 THEN GO TO 340
320 IF i = 2 AND p(i> > 16 THEN GO TO 340
330 GO TO 280
340 NEXT i
350 IF p«U < = 21 AND p<3> = 5 AND <p<2> <> 21 OR
p (4) < > 2) THEN GO TO 380
360 IF p(l) =21 AND p(3> = 2 AND *p<2 <> 21 OR
4 p < 4) <> 2>> THEN LET b - b#1.5 - PRINT
FLASH 15 AT 5, 18; "BLACKJACK" J GO TO 380
370 IF (p 12) <= 21 AND p(2) >= p < 1) > OR pU) >21
THEN LET b = O
380 LET m = n»+2*b
390 GO TO 130
500 LET p(i+2) » p (i +2 > +1
510 LET c = TNT (13* RND >+2
520 IF c = 11 THEN LET a = a+1
530 LET p (i> = p(i)+c*Ic < 12) + 10* <c > 11 >
540 IF p(i) <22 OR a = 0 THEN GO TO 570
550 LET a = a-1
560 LET p <i> = p <i)-10
570 GO SUB 8500
5S0 GO SUB 9000
590 PRINT INK Oi AT 11*1-2, 9* p<i>
600 RETURN
30
BOOO
DATA
o.
78, 209, Bl, Bl, SI, 70,
0
8010
DATA
102
, 255, 255, 255, 126, 60,
24,
24
8020
DATA
24,
60 f 126, 255, 255, 126,
60,
24
8030
DATA
24,
60, 126, 255, 255, 219,
24,
60
8040
DATA
60,
60, 219, 231« 231, 219,
24,
24
SOSO RESTORE 8000
8060 FOR k = USR "e 1 * TO USR "e ,, +39 * READ x ±
POKE k. k i NEXT k
BO70 RETURN
8500 LET p = ll*i-7 t LET q = &*pfi+2>-5
8510 INK 5 ; FRINT AT p-3, qS
" GRft 5 ERA 3 S Hft 3 Gflfl 3 GRfl 3
ERA SHI 5" i FOR k - 1 TO 5 s
PRINT AT p-3+k, q; 11 £BB 5
GRA SHI 5" S NEXT k *
PRINT AT p+3, q; M ERA 1 SB6 3
GRft 3 Gflfl 3 GRA 3 ERA 2" * INK O
8520 LET suit = 1+ INT (4* RND > * INK 2*(suit
- PRINT AT p—2, q+3; CHR* (148+suit)
8530 RETURN
9000 LET x * USR "a"
9010 FOR k = O TO 31 - POKE x + k, O s NEXT k
9020 LET s = CODE b* (0 + 15360 * IF b*Cc? = "
THEN LET s = USR "e M
9030 FOR j = O TO 7 * LET y - PEEK (s+j) f LET
* LET d = 256
9040 FDR k = 8 TO 1 STEP -1 * LET d - d/2 * IF
THEN LET c = c+3*d*d * LET v = v-d
9050 NEXT k
9060 LET h = INT (c/256) s LET L = c-256fh
9070 POKE x, h * POKE x + i, h s POKE x+8, L -
POKE x +9, L
9080 LET >: = x+2+8*<j - 3>
9090 PRINT AT p, q+2; " GRB A GRR B'* 3 AT p+1,
'■ GRfl C ERA D T|
9100 NEXT j
9110 RETURN
4
< 3)
T H
c ® O
y V- d
q+2i
31
Fruit Machine
Copyright ft) by Beam Software
This program simulates the fruit machines to be found in
pubs and gambling parlours.
The. main benefit of gambling here of course is that if you
should lose the 10 pounds you tame in with, it doesn't matter
too much. Of course the main drawback is similar - you can't
take your winnings with you.
This program of FRUIT MACHINE will extend the concepts you
may have about the applications of the user defined graphics.
In this program we will define 60 user defined characters for
the J6K version, and an additional 40 for those with more
memory. In fact on a 48K machine many more graphic characters
could be defined with no additional programming required.
So step right up, ladies and gentlemen, and try your luck!
At the very least, you'll be amazed at the graphics of this
program.
You obviously win if you get all three windows showing the
same picture, with different amount depending on the picture.
If you get two adjacent windows with the same picture, you
also win, except if it's two lemons.
Programming considerations;
The design of this program is for a fruit machine with three
cylinders, each rotating independently. Each "window" is
comprised of 20 characters <4 across, 5 deep), each possibly
showing the picture of a different symbol - lemon, bell,
cherry, etc.
As ojtiy 21 graphic characters are allowed, this immediately
places restrictions on what we can do. Fortunately for us, we
do not need to have all 60 (or IQ0 or whatever) characters
specially defined at the same time.
Once a graphic character has been written to the screen, the
memory locations corresponding to that position on the screen
will keep that shape, and not lose it until you overwrite it.
What you do with the graphic character you defined is not
important.
As an example, let^s assume we define A as BIN 01010101, BIN
lOlOlQlQ, BIN 01010101, etc., and that we said
PRINT AT 0,0; "A"
then the eight memory locations corresponding to (0,0) would
remembered this as BIN 0101010I, BIN lOlOlOlQ, etc,, and not
as "A 11 . We can change the definition of A and it will have no
effect on the screen. This is not the case with all computers.
32
This program therefore draws shapes, then redefines the
characters, draws again, and sd on.
Program structure:
100 - 200
950 - IBID
2000 - 2230
Define variables
Draw fruit machine
and check that player Is solvent
Main loop
For each window
For each of 3 to 6 displays
Choose a picture
For each of five lines
Redefine character set
Print up each block
Next Line
Next display
Redefine character set
Next window
2500 - 2560
Calculate winnings if any
The program gets all its information from DATA statements,
including which ink and paper colour to use in drawing the
next block.
Fitting the program in 16K;
The program as it stands will NOT fit Into 16K. DATA
statements are not a particularly efficient way of storing
information (see notes in METEOR STORM), and no steps have
been taken to minimise memory usage.
The version included here has 4 different pictures possible:
Cherry, Lemon, Bell and Pineapple. As well, at the beginning
of each pull of the lever, all windows are reset to show a
large question mark.
The program can be modified to fit into 16K very easily with
the following changes:
Only 3 pictures are possible: Cherry, Lemon and
Bell.
At the beginning of each pull of the lever, each
window will show a cherry#
To effect these alterations, the following is required:
33
* Delete lines 8000 - 8053 (defining the question mark)
- Delete lines 8400 - 8453 {defining the pineapple)
* Delete lines 9010 and 9400 (defining ink and paper for
question mark and pineapple)
* Change line 2040 to read
LET picture - 1 + TNT ( 3 * RND )
This limits the choice to 3 pictures
* Change lines 55lO t 5520, 5530 to read
LET pattern = 1
LET picture - 1
LET oldpict - 1
This sets up the cherries instead of the question
marks *
Using some of the space saving techniques described
elsewhere in the book, it should be possible for you to fit
alt of the program within 16K« (Try it as a programming
exercise!)
4
you have £9-5 left
Press <ENTER> to pl3y
34
FRUIT MACHINE
100 LET fillhirEs = 5300
UO LET drawblock = 5100
120 LET first = 5
130 LET resethi res “ 5500
140 LET blankwindow = 5700
150 LET money = JO
160 DIM r(3)
170 DIM s(4)
100 RESTDRE 7000
170 FOR k = l TO 4 s READ sCk) * NEXT k
200 INK 7 i PAPER 5 * BORDER 5 ? CLE
950 REM draw*fruit*machine
980 LET c* =
•' ERA SH I 8 SRfl SH I a GRfi SMI 8 t?RA SMI 0
ERA SR I 0 ERA SH I 0 GRfl SHI 0 GRfl SRI 0
ERA SH I S ERA SH I 8 GRA SHI 8 ER ft SHI 0
gRA 0 qRft q HI 0 q QA SHI 0 ERA SHI 0 M
1000 PRINT AT 1, 5? " G Rft 4"; c*3 •* ERR SHI 7"
1010 PRINT AT 2, 4; H gRfi 4 ERR §JiI Q" ;
C»; " GRft SHI 0 GHfl SHI 7"
1020 PRINT AT 3, 3; " ERR 4 QRft SHI 8 ERR SH I B"3
«=*5
" GRft SHI B GRfl SHI B Gftfl SHI 7** ERA 4"
1030 PRINT AT 4 , 33
M ERA SHI 0 GRft SHI 0 GRA SHI 0";
c*3
" ERA SHI
B GRA SHI
8
GRA
SR I
0
GRA SHI a
ERA SHI 5*
1040
PRINT
AT 5. 3i
" GRA SHI 0 GRA SHI 0 GRA
SHI
8" »
" GRA SNI
B GRA SHI
0
ERA
SH I
B
M *
g q.ft 3 H l 8
qpp i 5"
1050
PRINT
AT 6, 35 '*
GRA SHI B
GRA SHI 8
* * *.
* ERA SHI
0 ERA SHI
9
GRA
am
0
A ERA SHI
8 GRA SHI
9
GRA
SHI
0
* * *
A ERA SH1
8 GRA SHI
8
A, A
G0O SHI 0
GPQ ^^1 5 «
1 060 JF'ffINT
AT 7, 3i h
GRA SHI 0
GRA SMI 0
* * *
* GRR SR t
0 ERA SHI
8
SiiS
am
8
* A A
* ERA SHI
0 GRA SHI
8
ERA
SHI
B
*
A GRA SHI
8 GRA SHI
8
A A
GRA SHI B
ERA fin 1 5 m
1070
PRINT
AT B, 3; i!
GRA SHI 0
GRA SHI 0
AAA
A GRA SHI
0 GRA SHI
0
GRA
SH 1
B
AAA
^ G 0A SHI
8 GRA SHI
B
GRA
SH I
8
AAA
ERA SHI
B GRA SHI
0
A A
GHB 5 M
1O0O
PRINT
AT 9, 33 "
GRA SHI 0
GRA SHI B
AAA
A ERA SHI
Q ERA SHI
0
£E£
SH.. 1
9
AAA
GRA SH I
B GRA SHI
0
GRA
SMI
a
AAA
GRA SH I
8 e«a SH1
a
A A
GRA 3"
1090
PRINT
AT lO, 35
11 GRA 5 H I 0 GRA SHI J
B
AAA
* GRA SH1
0 ERA SHI
e
ERA
SH i
8
35
1100
.*** ma mi a ma mi e &rb mi a
„„ GRfi SHI 8 GRA sm e
** ^ 5"
PRINT AT 11, 3; " fiBfl mi B GHfl SHI 9 1 '3
C*3 " fi RQ SHI e GRA SHI 8 ERA ^ j-t \ 8
GRB SHI 8 fiRR $H J 3 SR ft SH I 3 ERA SHI 2“
1110
PRINT
AT 12
,
3; -
GRA
mi 8
ERft
SHI 8"
3 c*
3
" GRA SH J
a ERR SHI
8 ERA SHI
s Gp a an 1
a
1120
PRINT
AT 13
,
3;
" ERA SH t
a ERA SHI
8 SH l
8 ERA SHI
8
GRA
am
9
QR A
mi
B
ERft
SHI
9
EXT
^H 1
o
ma
l
a
ERA
SH I
8
ERft
SHI
9
ma
am
8
GRA
am
9
SH t
8
ERft
SHI
0
ERft
SH I
0
E >: t
SH I
7
GRA
SH I
a
GRA
SHI
8
ERft
5H I
a
GRA
SH I
a
GRA
SH I
e
GjRA
SHI
8
GRA
SH £
a*
1 130
PRINT
AT 14
i
3;
11 ERA SHI
B ERA Spi
8 GH ft SHI
8 GRA SHI
8
GRA
mi
a
ERA
SHI
8
GRA
am
8
am
0
ERA
SHI
9
ma
SHI
8
ERA
SH I
a
ERft
SH I
B
GRA
SH I
8
ERA
SH I
8
GRA
mj
8
ERA
SH I
8
fcrtX
am
7
Uiifcil
SH I
8
ERft
SH I
B
GRA
am
a
ma
SHI
8
ERA
SHI
8
ma
SH 1
8
E_R_ft
SRI
b"
1140
PRINT
AT 15
*
3i
*' GRft SHI
B GRA SH }
8 ERft SHI
8 ERA SHI
e
ma
SHI
8
ERA
SHI
B
mi
mi
0
£88
SH I
s
ERA
5H
0
ma
SHI
8
ERA
SH I
8
ma
SH I
a
GR ft
SHI
B
tma
SHI
9
ERft
SHI
8
ERA
SH I
9
ORB
SH 1
8
mi
SHI
7
&RB
mi
8
ERA
SH I
8
ERA
SHI
8
ma
SH I
8
ERA
SHI
8
sana
ffH \
8
h2Ll
S_H I
O
.«
1 150
PRINT
AT 16
r
3i
*' ERA SH I
8 GR ft SH I
B GRA SHI
8 GRA SHI
8
ORB
SHI
B
□ Rft
am
9
orb
SH I
e
ERA
SHI
e
ERA
mi
B
GRA
SH 1
a
GR ft
SH I
B
GRA
am
a
me
SHI
8
ERA
SHI
a
sh ;
a
ERA
SHI
8
ERA
SH I
8
fiPfl
SHI
8
ERft
SHI
B
GRA
SH I
s
ERA
SHI
B
ma
SH 1
8*
*
1 160
PRINT
AT 17
t
3; "
ERA
am s
EfR A
am e"
; c*
;
4 " ERR SHI 8 S P R SHI Q G R ft 5H I 8 ERA SH I 8
1500 GO SUB blankHindow
1750 IF money > 0 THEN GO TO 17BO
1760 PRINT INK 03 AT 20, 0; "Sorry ^al 1 *your
iidaney + i s *gone "
1770 STOP
1700 PRINT INK 0 5 AT 20, 0; " You .have **" 3 money;
11 t" ; AT 21 p 0, "Press
* < ENTER > *to*pl Ay ”
1790 INPUT k*
1800 PRINT AT 20, 05 *' ^ * ^** *„.^ „ ** * *
1810 LET money ~ money-.5
1920 PRINT INK 03 PAPER 0; AT 13, 13;
AT 14, 133 " 3 AT 15, 13;
1830 GO SUB blankwindow
36
2000 REM di spl ay^ali*windows
2010 FOR w = l TO 3
2020 FOR d = 1 TO 3+3* RND
2030 LET oldpict - picture
2040 LET picture = 1+ INT (4* RND >
2050 IF picture = oldpict THEN GO TO 2040
2060 FOR L “ 5 TO I STEP -I
2070 GO SUB Till hires
2080 LET p = O
2070 LET pattern - picture
2100 FOR b = L TO 5
2110 LET p = p+1
2120 SO SUB drawblock
2130 NEXT b
2140 LET pattern * oldpict
2150 FOR b - 1 TO L-l
2160 LET p = p+1
2170 GO SUB drawblock
2180 NEXT b
2170 NEXT L
2200 NEXT d
2210 LET rl w> = picture
2220 GO SUB resethi res
2230 NEXT w
2500 IF rfll <> r<2> AND r<2> <> r(3) THEN GO TO 1750
2510 IF r<2> = 2 THEN BO TO 1750
2520 LET win = 1
2530 IF rU) = r(2> AND r <2> = r <3> THEN
LET win « s (r (1 > )
2540 PRINT PAPER Oi AT 13, 13; "YOU"3 AT 14. 135
"WON"; AT 15, 13; 11 '■*; win
2550 LET money » money+wvn
2560 GO TO 1750
5100 REM get^correct^colours*tor*block
5110 RESTORE 9000+100*pattern
5120 FOR c * 1 TO b-1
5130 READ ink, paper
5140 NEXT c
5150 READ ink, paper
5200'REM print A one*block
5210 PRINT AT 4irst+p, 7*w-2;
5220 FUR c = 1 TO 4
5230 PRINT INK ink; PAPER paper; CHRS (144+4*b-5+c>5
5240 NEXT c
5250 RETURN
5300 REM rede* ine^hi^resolutI on^characters
5310 RESTORE 0000+1O0*picture+10*L
5320 FOR h = * USR "a"+32*L-32 TO USR "a"+32*L~I
5330 READ byte * POKE h, byte
5340 NEXT h
5350 RETURN
5500 REM def ine*hires 4 as/?"
5510 LET pattern - O
5520 LET picture = 0
5530 LET oldpict = 0
5540 FOR L = 5 TO 1 STEP -1
37
IF handle = O THEN
5550 GO SUB fillhires *
GO TO 5590
5560 IF L = 5 THEN PRINT AT 3, 27;
AT 4, 27; ; AT 5, 27; 11 [i£i£ 4/i
AT 0, 27; ” QBB 3JdJ S &RB 5Jd I 5”;
AT 9, 27J M SRm SHI 9 SEfi SHI 5"
5570 IF L “ 3 THEN PRINT AT 5, 27i ;
AT 6, 27? AT lO, 27;
M GRfl SHI 8 GRfl SHI 5"
5580 IF L = 1 THEN PRINT AT 7, 27; ,, „ H 3
AT 8, 27; “ AT 9, 27? "**" ;
AT 11, 27; 11 GRfi SHI 8 EBB SMI 5”
5590 NEXT L
5600 RETURN
5700 REM Fill*all*window5 4 with*7
5710 LET handle - 1 * GO SUB resethires *
LET handle = 0
5720 FOR y* = 1 TO 3
5730 LET d = 1
5740 FOR b = 1 TO 5
5750 LET p = b
5760 GO SUB drawblock
5770 NEXT b
57BO IF w = 1 THEN PRINT AT 7, 27;
“ GRfl SHI 8 SRfl SH I 5 ,T ; AT 8 f 27;
” GRfl SH 1 8 ERA S±L1 5” ? AT 9, 27?
11 GRfl mi B frRft mi 5"? AT 11, 27;
" GRfl SHI
2^"
5790
IF w = 2 THEN
PRINT
AT 5,
27;
■* GRfl 4
AT 6, 27;
..
GRfl
SHI 8
GRfl
SH 1
5 H ;
AT 10, 27!
M GRfl
5*"
5000
IF * — 3 THEN
PRINT
AT 3,
27J
** ERA 4
AT 4, 27;
■i
GRfl
SHI B
GRfl
5* 1 ;
AT 5, 27?
it
£LE10
mi B
GRfl
SH I
5";
AT 8, 27?
"
GRfl
5*" i AT 9,
27;
" A 5 i h
5610
NEXT w
5820
RETURN
7000
DATA 15, 3,
12, 7
8000 iREM Da t a * f or ^h i gh eso 3 ut j on i c tures
ifirst s*quest ion *mar k
8010
DATA
o.
o.
0, 0,
o.
O,
0,
O
soil
DATA
o,
0.
O, 3,
15
, 60,
112, 112
0012
DATA
Op
O,
0, 248,
252,
62, 14, 7
BO 1 3
DATA
o.
0,
o, o,
o.
0,
o.
0
B02O
DATA
o.
0,
0, 0,
0*
o.
Op
0
8021
DATA
224,
224, 224,
240,
240, 248, 240,
8022
DATA
3,
3,
3, 3,
3,
7,
6,
14
8023
DATA
o,
128, 128
, 128,
128, 0, 0, 0
8030
DATA
o.
o.
o, 0,
0,
o f
Op
O
8031
DATA
0,
o.
0, 0,
1,
1.
3,
3
8032
DATA
28
, 56, 112
» 224,
192, 128, O, O
8033
DATA
o,
o.
O, 0,
o.
0,
Op
0
BO 40
DATA
o.
o*
0, 0*
O,
o.
Op
0
BO 4 1
DATA
A
7, 3,
3,
1,
o.
0
0042
DATA
o.
0,
128,
192
, 192,
128, 0, 0
96
8043
DATA
o.
Of
0,
o.
0, 0,
o, o
0050
DATA
o.
Of
0>
0,
Op O,
0, o
8051
DATA
3,
15
, 15, 15, 3,
O, 0, 0
8052
DATA
o.
1 92,
192,
192,
O, 0, 0, 0
8053
DATA
o,
o.
o.
O,
o, o.
0, 0
8100
REM Cherry
8110
DATA
0,
0,
0,
0,
Op 0,
0, 0
Sill
DATA
0,
0,
0,
o.
0, o f
0, 0
8112
DATA
0,
6,
14,
30,
30, 62, 126
8113
DATA
0,
0,
o.
o.
o, o.
O, O
8120
DATA
0,
o.
O,
o.
0, 0,
0, o
0121
DATA
0,
0,
Ip
i t
Ip
2, 2
8122
DATA
127,
191
* 31
P 3,
0 , 0 , o, o
8123
DATA
o.
o.
O,
128, 128
p O, Op 0
8130
DATA
O,
0,
0,
Op
Op o,
Op 0
8131
DATA
4 »
4,
4,
4,
4, 4,
2, 2
S 1 32
DATA
o.
o f
o P
o.
O, 0,
0, 0
8133
DATA
0,
o.
o.
O,
Op o.
0, Q
B14G
DATA
0,
o.
o.
0,
1, Ip
Ip 1
8141
DATA
29
, 60,
126,
255,
255, 255, 255, 255
8142
DATA
224,
240
, 120, 124, 252, 254, 254, 254
8143
DATA
0,
0,
0,
0,
o, o.
O, O
8150
DATA
1,
u
Op
Op
0, 0,
0, 0
8151
DATA
255,
255
, 255, 127, 63, 31, 7, 0
8152
DATA
254,
254
, 252, 252, 248, 224, 128, 0
8153
DATA
o.
Of
o.
O,
O, 0,
o, 0
8200
REM Lemon
8210
DATA
0,
Of
0,
0,
0, 0,
0, 0
9211
DATA
0,
Of
0,
o.
0, o.
0, 1
0212
DATA
o.
Op
Op
o.
0, 0,
127, 255
B213
DATA
0,
0,
0,
0,
o, o.
16, 188
B220
DATA
Of
0.
0,
Op
Ip Ip
3, 7
S221
DATA
7,
31
, 127,
255,
254, 248. 240. 224
8222
DATA
255,
255,
255, 255,
15, 15, 31, 63
8223
DATA
254,
254,
126, 60,
196, 246, 254,
254
8230
DATA
7, 15, 31
p 31, 63,
63, 63, 63
8231
DATA
192,
193,
199, 255,
255, 255, 255,
255
8232
DATA
127,
255,
255, 255,
255, 255, 255,
255
8233
DATA
254,
254,
254, 254,
254, 252, 252,
252
8240’
DATA
63,
63, 63, 63, 63,
63, 31, 31
8241
DATA
255,
255,
255, 255,
255, 255, 255,
255
B242
DATA
255,
255,
255, 255,
255, 255, 255 T
255
8243
DATA
248,
248,
240, 224,
224, 192, 128,
0
0250
DATA
63,
63, 63, 63, 31,
O, O, O
8251
DATA
255,
255,
255, 255,
0 , O, O, o
8252
DATA
254,
248,
224, 128,
0, O, O, O
8253
DATA
O. 0
p o.
O
O
O
o
p o
8300 REM Beil
8310 DATA 0, O, O, O, O, O, 0, 0
8311 DATA Of Of 3, 14, 8, B, 12, 6
8312 DATA O,
B313 DATA O,
8320 DATA O,
9321 DATA 3,
8322 DATA 192, 240, 252, 254, 254, 255, 255, 255
8323 DATA 0, 0, 0, O, O, O, O, O
192,
112,
16,
16, 48, 96
O, 0,
o.
0, 0,
0
O, O s
Op
O, O,
o
63,
127,
127,
255, 255, 255
8330
8331
8332
8333
8340
9341
8342
8343
8350
8351
8352
B353
8400
8410
841 1
8412
8413
8420
8421
8422
8423
8430
8431
8432
8433
8440
8441
8442
8443
8450
8451
8452
8453
7000
7010
7100
9200
9300
7400
DATA
0 , 1 , 1, 1, 1,
U J # 1
DATA
255, 255, 255,
255, 255,
255,
255,
255
DATA
255, 255, 255,
255, 255,
255,
255,
255
DATA
0, 12B, 12B, 12B, 128, I2B, 12B, 120
DATA
1 , j 3, 3, 3,
7, 14, 56
DATA
255, 255, 255,
255, 127,
127,
127,
255
DATA
255, 255, 255,
255, 255,
255,
255,
255
DATA
128, 192, 192,
192, 192,
224,
240,
252
DATA
31, 3, O, O, 0
, 0, o, o
DATA
255, 255, 3, 3
, u o, o.
0
DATA
255, 255, 128,
128, O, 0
, 0,
0
DATA
252, 192, O, O
O
O
o
0
F>EM pineapple
DATA
0 , 0 , 0 , 1, 1,
9, 13, 7
DATA
0, 4, 4, 14, 142, 158, 254, 189
DATA
O, 64, 68, 196
, 220, 221
, 247
, 245
DATA
0, 0, 16, 112,
224, 192,
12B,
184
DATA
7, 3, 3, 1, 1,
0, O, 0
DATA
187, 221, 219,
235, 247,
251,
253,
255
DATA
245, 250, 253,
251, 247,
239,
223,
223
DATA
240, 224, 192,
128, 128,
0, 0
* 0
DATA
0, 0, 0, 0, 1,
1, 3, 3
DATA
127, 127, 80,
219, 219,
219,
39, 178
DATA 254, 254, 46, 111, 227, 29, <73, 125
DATA 0, Q, O, O, 128, 12B, 128, 192
DATA 3, 3, 3, 3, 3, 3, 1, 1
DATA 192* 1B3, 70, 57, 53, 53, 174, 209
DATA 200, 215, 27, 1B7, 145, 1B3, 119, 191
DATA
192, 192,
192,
192,
128,
120, 128
DATA
1, 1, o,
0,
0,
0, 0,
0
DATA
219, 255,
197,
237,
237,
127, 31,
DATA
147, 107,
27,
218, 190,
252, 248,
DATA
0, 0, 0,
0,
0,
0, O,
0
PEW i nk, paper
*Tor *each
*block
DATA
0, 5, 0,
5,
0,
5, 0,
5,
O, 5
DATA
4, 1, 4,
u
4,
t* 2,
u
2, 1
DATA
6, 4, 6,
4,
6,
4, 6,
4,
6, 4
DATA
7, 2, 7,
7,
2, 7,
2,
7, 2
DATA
4, 3, 4,
3,
6,
3, 6,
3,
6, 3
40
Line Renumber
PC
os
13
tc- £8
P3
3E
0 2
*'
Ft
r 3
FE
ec o*
OS
fti
BP
F i
C ! P4
C5
10
*£
or
06 3 ?
IP
C3
*£
■pe
o -c
«* C3
'‘jy
P5
"?►*
e> ;
Bubble Sort
Copyright (c) by Beam Software
There are all sorts of people interested in computing*
but in mathematics the word f sort’ has a different
meaning. There are indeed many different sorts of sorts*
A sort is a process by which you can create order out of
chaos, and usually the sorting process is applied to a
large number of names or an array of numbers.
The program given here serves as both a demonstration of
the processes involved in the sorting process, as well as
being the basis for a compact subroutine you can use in
your own programs - for example to sort a list of names
and addresses, or to sort a hand of cards in a bridge
game.
The demonstration of these sorts given here is
graphically very enjoyable as well as being slow enough
to allow a good understanding of the sorting process*
The bubble sort:
The first program given here is a traditional bubble
sort. What the program does is that it compares two
numbers adjacent in a list: if the numbers are the wrong
way round (in other words the larger number comes before
the smaller number) then it swaps them around*
If you run this program, you will soon realise why it is
called a bubble sort - the smaller numbers seem to bubble
to the top and the larger ones bubble to the bottom.
The program will keep on swapping adjacent numbers, over
and ovpr again, each time getting the list of numbers a
little bit more sorted than before until finally there is
no more sorting to be done.
The program is very cute in its execution, and you can
see how hard the dumper truck has to work to sort the
mess out.
You will soon realise that there must be a better way to
sort things*
Modified bubble sort:
The second program listing is a modified bubble sort* Now
the program is no longer concerned to swap merely
adjacent numbers - it is prepared to roam much further
afield.
41
This cuts the number of swaps to be done to about half
those on a traditional bubble sort*
You can either enter the second program as listed* or if
you have already entered program l t all that is needed is
to change lines 320, 330, 340, 300 and 510.
Sort subroutine;
Aside from its demonstration purposes, you can use sorts
in your own programs* Program 3 gives the listing of the
modified bubble sort in subroutine form (lines 8000 -
8030) which you can use in your own programs*
This subroutine assumes the numbers to be sorted are in
an array p(n), and that n is the number of elements to be
sorted.
Program 3 can be obtained from Program 2 by deleting
lines 110 - 130 and lines 280 onwards, and then inserting
new lines 280 - 300, 1000 1040, and 8000 - 8030*
As you can see from this program, 15 numbers can be
sorted in about 3 seconds, including the time required to
print the 15 numbers twice.
6.3883362
18*1362
11.215912
2,1936542
15 . 914-386
9*6141963
2.0718536
6.4043157
13 . 911632
9,3734465
14.39119
18.341049
11,579376
14.456252
1,371933JI^
SORT VERSION i
lOO BORDER 7 * PAPER 7 = INK O 5 OVER 0 * CLS
110 RESTORE 600
120 FOR i * USR "a*’ TO USR
130 READ x * POKE i „ M * NEXT i
140 LET n = 15
150 DIM p<n>
160 PRINT "Do * you ant * to * choose *your
**number5 A (y *or *n>7‘*
170 LET b* - INKEY* * IF b* = MW THEN GO TO 170
ISO IF bl = “n" OR b* = "N" THEN 60 TO 240
190 PRINT **Enter * 15^numbers*t d A be A sor ted K
200 FOR y = 1 TO n
210 INPUT p <y) i PRINT p{y>
220 NEXT y
230 GO TO 270
240
FOR x *
1 TO n
250
LET ptx)
= 15*
RND +1
260
NEXT x
270
CLS
200
FOR x =
1 TO n
290
PRINT AT
x f OS
p < x )
300
NEXT x
310
LET m =
IB
320
FOR 1 =
n-1 TO
1 STEP -1
330
FOR j =
1 TO i
340
LET L -
j+1
350 IF p(j) <=* pIL) THEN GO TO 500
360 LET b* ^ H *„**„„"( TO LEN STR* p(j>)
i PRINT AT j, 01 OVER li PAPER 5? b*
370 IF L = m THEN GO TO 390
390 FOR x = m TO L STEP SGN <L~m> ? PRINT INK 23
AT x f IB 3 " mn A s ma B C" 3
AT x + SEN IB; " * *i*' * NEXT x
390 LET y - LEN SIR* p<L> s FOR x « 17 TO y STEP “1
s PRINT INK 23 AT L p x;
M IjRfl A SRft & GRfl C 4 " - NEXT x
400 FOR x = O TO 10 * PRINT AT L, «3 “ -."*1 P<L>;
* INK 2; « ftRR A E&B B ERA C" * NEXT X
410 FOR x » L TO j STEP -1 * PRINT AT x T 1 ! 3 p(LM
INK 2; " GHfl A ERR B fiRft C ri ; AT x+l* 111
M _- NEXT x
420 PRINT OVER i; AT j f O; p<j)
430 FOR x - j TO L s PRINT OVER 1| AT x p O; p<j)5
AT x, OS p C j > * NEXT x s PRINT AT L p 03 p < j >
440 FOR x - 10 TO 0 STEP -1 * PRINT AT j, x; p(L>3
INK 2? H tj»RA A SB B B ERR C" ; " * M s NEXT x
450 FOR x - y TO 17 t PRINT AT Jf Ki INK 23
•' * ERR A ERR R GRfl C M f NEXT x
460 LET m — j
470 LET t = ptL)
480 LET p CL) = p(j>
490 LET ptj> - t
500 NEXT j
43
510 NEXT i
520 FOR x - m TO 10 s PRINT AT x, IB; INK 2;
« GRfl A QRA B GHG C“? AT X-l , 10> ” *
NEXT x
530 PRINT AT 21, 0\ " Do ^you * want *ta .sort
^again?*"
540 LET b4 " INKEY* * IF b* - "" THEN BO TO 540
550 IF b* — H y " OR b* = M Y“ THEN RUN 100
560 IF b* « "y' 1 OR b* - 11 Y" THEN RUN iOO
600 DATA 0, 0, 2, 6, 15, 30, 63, 254
610 DATA O, O, 63, 127, 24J, 100, 238, 4
620 DATA 63, 255, 241, 228, 158, 223, 14, 4
SORT VERSION 2
100 BORDER 7 * PAPER 7s INK O i OVER 0 * CLS
110 RESTORE 600
120 FOR i = U5R M a w TO USR
130 READ x * POKE i, x * NEXT i
140 LET n - 15
150 DIN p(n)
160 PRINT M Do *you*want*to^choose^yaur*own
* * numb er ^ ^ < y A or ^r> > 7 "
170 LET b* = INKEY* = IF b* — " " THEN GO TO 170
180 IF b* = “n’ 1 OR b* - "N* THEN BD TO 240
190 PRINT "Enter * 15 ^number s*to*be * sorted"
200 FOR y = 1 TO n
210 INPUT p < y > t PRINT p(y>
220 NEXT y
230 GO TO 270
240 FOR x = 1 TO n
250 LET p<x) - 15* RND +1
260 NEXT x
270 CLS
200 POP x = 1 TO n
290 PRINT AT x, 0| p<x>
300 NEXT x
310 LET m = 18
320 FOR j — 1 TO n—1
330# FDR i = j + 1 TO n
340 LET L = n+j-i+l
350 IF ptj> <= p(LI THEN BO TO 500
360 LET b* = '■**„**„*"€ TO LEN SIR* p<j>>
s PRINT AT j T 05 OVER IS PAPER 55 b*
370 IF L = hi THEN GO TO 390
380 FDR x ±= m TO L STEP SGN <L-ro> ? PRINT INK 2;
AT x, 10; " 68A A ERA B GRfl C - i
AT x+ SGN (m-L ) , 101 "***" s NEXT x
390 LET y = LEN STR* pCL) s FDR x - 17 TD y STEP
t PRINT INK 2; AT L, *5
'• G BB A GRfl B Pfift C*" - NEXT X
400 FOR x “ O TO 10 * PRINT AT L, k; " *'* 1 p CL) 5
INK 2; '* ERA A fiflfl & GRfl C" i NEXT X
410 FOR x = L TO j STEP -1 - PRINT AT x, IIi p<L>
INK 25 M GRfl A GRfl & GELft C* 5 AT x + 1, 11?
"***„*„*****/' 5 NEXT k
420 PRINT OVER U AT j, 0; p<j>
430 FOR x = j TO L * PRINT OVER 13 AT x, 03 P*j>5
AT x, 0; pCj) = NEXT x s PRINT AT L, 0 3 p <j>
440 FOR x = 10 TO O STEP -1 * PRINT AT j, xl p(L>i
INK 23 " GHfl A £R8 P GRA C 1 ' 3 * NEXT X
450 FOR x = y TO 17 * PRINT AT j, * 3 INK 25
" A RRA a GRA B £RA C" S NEXT x
460 LET m = j
470 LET t = p<L>
400 LET p(L> = pCjJ
490 LET p(j> = t
500 NEXT i
510 NEXT j
520 FOR x = m TO 18 * PRINT AT*, 103 INK 23
" GRR A GRR B SRfl C" 5 AT x-l f 18; -
NEXT x
530 PRINT AT 21, 03 1, Do i yDu i want i to i 5ort
iagaifi^* M
540 LET b* = INKEY* * IF b$ ” "“ THEN SO TO 540
550 IF b* « n y" OR b* = "Y" THEN RUN 100
560 IF b* = “y 1 * OR b* = **Y" THEN RUN lOO
600 DATA O f O, 2, 6, 15, 30, 63, 254
610 DATA O, O, 63, 127, 241, 100, 23B, 4
620 DATA 63, 255, 241, 228, 158, 223, 14, 4
4
43
INK O
OVER 0
CLS
SORT VERSION 3
100
140
ISO
160
170
180
190
200
210
220
230
240
250
260
270
280
290
300
1010
1020
1030
1040
8000
8010
8020
8030
BORDER 7 * PAPER 7 t _ _
LET n = 15
DIM p(n)
PRINT "Do j. you*want A to*choose A your *own
* ^numbers*fy ^or*n > 7"
LET b* - INKEY* i IF b$ = 1,11 THEN GO TO 170
IF b* = "n" OR b* = "N" THEN GO TO 240
PRINT "Enter * 15^numbers *to*be A stJrt ed"
FOR y = 1 TO n
INPUT p <y) s PRINT p(y)
NEXT y
GO TO 270
FOR x = 1 TO n
LET p(x) = 15* RND +1
NEXT x
CLS
GO SUB 1000 * GO SUB 8000
GO SUB lOOO
STOP
FOR x = 1 TO n
PRINT fiT x, O; p(x>
NEXT x
RETURN
REM sort *subrouti ne
FOR j = 1 TO n-1 ? FOR i — j+1 TO n -
LET L “ n+j-i+1
IF p(L> p<j> THEN LET t * p<L) s
LET p CL> = p(j> * LET p<j) = t
NEXT i * NEXT j * RETURN
*
46
Simultaneous Equations
Copyright (c) by Beam Software
This program solves two simultaneous equations of the type
ax + by + c = D
This equation is the general form of equation for a straight
line* and the 'solution' of two such lines is the mathematical
term for the point where the two lines cross.
You will be asked by the program to enter the values of a f b
and c for each of the two equations* and the program will find
out for what values of x and y the lines meet.
if there is no solution - in other words the two lines are
parallel and do not meet - the program will tell you so.
The program will then draw for you each of the two lines and
show you where they cross.
Program structure:
The actual calculation part of the program is fairly small -
most of the program consist of getting the correct information
from you, and then displaying the results to you (including
the graph!.
Line 830 calculates the determinant D, If D is zero* no
solution exists.
The block from 900 - 990 determines in which quadrant the
intersection of the two lines occurs* and in which direction
the graphs should be plotted*
47
SIMULTANEOUS EQUATIONS
100 REM EQUATION
iOt REM
110 REM multansous* equation
120 BORDER 7 s INK 1 - PAPER 7 s FLASH 0 * INVERSE 0
c CLS
130 PRINT AT 0, 5| INVERSE U
"SIMULTANEOUS*EQUATIONS”
140 PRINT AT 2, 05 INK 2; INVERSE 13
"alX+biY+c1 ^ O”
150 PRINT AT 2, 16 5 PAPER 6 3 INK O! "a2X+b2Y+c2 - 0 M
IfcO PRINT AT 4, Oi "al = ■' 3 AT 4. 16 5 ,f a2 = "5
AT 5, 05 n bl = '*5 AT 5, 165 ,J b2 = “ 5 AT 6, 0;
“cl = " 5 AT 6, 16 5 ,f ir2 = "
170 DIM C (6« - REM coeUcient *arrav
ISO DIM S4t7)
190 DIM X*57)
200 DIM YS(7)
500 REM
510 REM inputrst^equation
520 FOR I = 1 TO 3
530 PRINT AT I+-3, 3; FLASH li '* > " 3 FLASH 05 INK 25
INVERSE 15 * A *****_*'
540 INPUT 5* ± LET CU) = VAL St
550 PRINT AT I+-3, 35 *' *_*********"3
AT 1+3, 43 ABS CU)
560 IF SGN CUJ = -1 THEN PRINT AT 1+3, 3;
S70 NEXT I
600 REM
610 REM 1 nput * 5 econd*equation
620 FOR I ^ 4 TO 6
630 PRINT AT I, 19; FLASH 13 " > " 5 FLASH O?
PAPER 65 "„**********“
640 INPUT S* * LET CU) ~ VAL S*
650 PRINT AT I. 195 "************ * H S
AT I, 201 ABS CU)
660 IF SON C(I> = THEN PRINT AT I * 19; “W*
670 Ji EXT 1
800 REM
810 REM calcul atution
820 PRINT AT 7, 05
830 LET D = C-C2-)*C(4)-C<l>tC(5>
840 IF D s O THEN PRINT INVERSE 15 11 DEGENERATE ^ M 3
INVERSE 05 "^“5 FLASH 1; - NO *SOLUT IONS’ 1 t
RUN
850 LET A = < C 53>fC15 > —C C2)#C(6>)/D
S60 LET X* = STRf A s LET A = VAL X*
870 LET & = t C U > *C < 6) -C (-3) * C (4 > > / D
880 LET f* * 3TR* B i LET & = VAL Y*
S90 PRINT INVERSE 13 "SQLUTIONS"5 INVERSE 05
" XS; U *^Y - *“5 v*
900 REM
910 REM olot^axis
920 IF A >= 0 AND B >= O THEN LET ok - 72 : *
LB
0
AT S ? 0
LET oy — 0 - PRINT AT 21, 8?
; AT 21, 23? M X“
930 IF A >= 0 AND B < 0 THEN LET an = 72 t
LET ov 3 HI * PRINT AT 8, Qi “D” ; AT 21- 8;
"Y“S AT 8, 23| "X"
940 IF A < 0 AND B >- O THEN LET an = 183 s
LET oy 3 = O * PRINT AT 21, 23! "O’*? AT 21, S;
"X"! AT 8, 23 5 A, Y"
950 IF A < O AND B < 0 THEN LET ok = 183 *
LET oy = 111 i PRINT AT 8, 23; “O" I AT B t 8;
AT 21, 23; “Y"
960 LET dx = t SON A 0)-C SGN A < 0>
970 LET dv = < SGN B >* OJ-< SGN B < O)
980 PLOT ox, ov - DRAW INK 0; d**l 11, 0 *
PLOT ox, oy i DRAW INK 0; 0, dy*lll
990 SO SUB 1500 s REM plot*! me*
lOOO INPUT "More^eQuatlon?<y 4 or*n>"; k*
IlOO IF k* = '*n“ OR k* = "N " THEN STOP
1110 IF k* = *V f PR k* ** "Y" THEN RUN
1120 80 TO IOOP
1500 REM
1510 LET rx - ABS (55/A> s LET ry = ABS (55/B)
1520 REM draw*First*1ine
1530 PRINT AT 2, 0; INK 2; OVER l; FLASH ti
1540 IF C<1) - O THEN LET 1x1 = O s
LET iyl = -CC3>/C(2l i LET ix2 = 2*A £
LET iv2 = iyl - GG TO 1620
1550 IF C(2) — O THEN LET iyl ^ O t
LET 1x1 = -C(3)/Ctn * LET iy2 » 2*B -
LET ix2 =ixl s 60 TO 1620
1560 LET ix1 = 2*A * LET iyl = -(C(3)+C(II*ix1»/C(2>
1570 IF dyliyl < O THEN LET ivl * 0 * BO TO 1590
1580 IF i ABS ivl- ABS <2*B>> > O THEN LET iyl = 2*B
1590 LET ix2 = O s LET i y2 = -C'3>/C(2!
1600 IF dv*i v2 < O THEN LET >1 v2 — O - GO TO 1620
1610 IF < ABS iy2- ABS (2*B>J > O THEN LET :y2 = 2tB
1620 PLOT ox+rxIlxL oy+ry*iyl
1630 DRAW (ix2-ixlMrx 4 (iy2-iyl)*ry
1640 PAUSE 100
1650 PRINT AT 2. 05 INK 2; INVERSE 13
" a 1 A+b 1 Y+c 1 = 0*'
I BOO REM
JBIG
1820
1 830
1840
1850
1360
1870
1080
REM draw *second A 1 i ne
PRINT AT 2
INK 0 3 *'
PLOT OVER
DRAW OVER
IF C<4> =
LET iy3
LET iy4
IF C<5> =
LET ix 3
LET ix4
LET 1x3 =
IF dv*iy3
, 16; OVER i; FLASH i; PAPER 6;
1; ox+rxlixK oy+ry*iyl
l; dx2-ixl)lrx, Uy2-iyU>ry
0 THEN LET 1x3 = O '
= -C<6)/C<5) - LET 1x4 = 2*A t
« iv3 s GO TO 1930
0 THEN LET iy3 = O ~
= —Cf6>/C(4 ? = LET iy4 - 2*B =
= ix 3 * GO TO 1930
2*A £ LET iy-3 = -<C <6>+C (4? *ix3>/CT5>
< O THEN LET iy3 = O s GO TO 1900
49
1890 IF t, ABS iy-3- ABb C2*& )l 0 I HEN LH iv3 =
1900 LET ih 4 0 = LET i y4 = —C(6> /Ct5>
1910 fF dy*iy4 < O THEN LET iv4 = O ± 60 TO 1930
1920 IF ( ABS iy4— AB5 (2*B> > > O THEN LET i y4 *
IV 30 BLOT ox + i ;; : *r ^ ( oy+iy3 *ry
1940 BRAN < i k 4—i x3> #rj< * *ly4-iy3)fry
1950 PAUSE 1O0
I960 PRINT AT 2, lb; INK 0; PAPER 6 \ "*2X+b2V+c2
1970 PLOT QJt + ixlIrx. oy + iyUry
I9SO DRAW <i si2—i Xi ) tr k « (iy2-iy 1 ) #ry
3990 RETURN
4
2*B
2*B
= O n
50
Space Escape
Copyright (c) Clifford Ram&haw
DESCRIPTION
You have been captured by the ALIEN and you are
stranded in a tower guarded hy an ALIEN ROBOT.
You have to contend with the force of gravity
dragging you to the ground and the ALIEN'S powerful
tractor pulling you back towards the tower.
More than that, once the ALIEN ROBOT discovers that
you are escaping, it will then shoot at you with the high
power suction laser beam. Once you are shot, you will
then be sucked back and put into the prisoner tower
again.
GOOD LUCK IN YOUR ESCAPE PLAN !!
HOW TO RUN THE PROGRAM
To start the program, type RUN CENTER).
Use 'w 1 key to move up, 1 dkey to move forward.
You have to move above the prisoner celt level before
you can move forward. Unless you move forward, you will
be continually sucked backward until you are back to the
tower again. Similarly, you will be falling down back to
tne celt level if you don't press *w’.
The game will halt every time you are shot or you
escape successfully.
Press any key to start another game.
4
FROGRAM STRUCTURE
This program uses special USER DEFINED GRAPHIC
characters to draw the ALIEN ROBOT and your space-craft
shape.
A close to real-time counter is maintained by using
the frame counter to record the time you lasted before
being re-captured by the ROBOT or if you are lucky, the
time you took to escape.
The structure of the program is as follows:
INTIALTSATION
SET SCREEN VARIABLES
SET USER DEFINED GRAPHIC CHARACTERS
51
main loop
DRAW TOWER SHAPE AMD SAFETY MARGIN LINE
INITIALISE VARIABLES
LI: STORE OLD POSITION
CALCULATES NEW POSITION
IF NOT MOVING FORWARD
generate sound tore
DRAW ALTERNATE SHAPE OF SPACE CRAFT
IF REACHES MARGIN LINE
prepare message
goto Tl:
IF NOT FIRE AND RND(,9
goto LI:
IF FIRE-FLAG NOT ON
set fire-flag
calculates final position for ROBOT
BLANK OLD ROBOT
MOVE ROBOT TOWARDS FINAL POSITION
DRAW NEW ROBOT
IF FINAL POSITION NOT REACHED
goto LI:
FIRE LASER BEAM ( PLOT Sr PLOT OVER )
IF NOT HIT SPACE CRAFT
goto LI:
PERFORM DRAW BACK ROUTINE
PREPARE MESSAGE
Tit CALCULATE TIME LAPSE
PRINT FINAL MESSAGE
SPECIAL NOTE
The TIME LAPSE before the game ended successfully or
tragically Is affected by the time taken up by any sound
generation within the program; but it is close to
real-time *
At the end of the game, any key pressed will restart
the game.
o
52
SPACE ESCAPE
100 REM ESCAPE
i 10 REM SPACE *ESCAPE
120 GO TO 8000
500 REM
510 REM deflne*ship*shape
520 FOR I - USR "A JP TO < USR ”J"+7>
550 READ m i POKE I, w
570 NEXT I
580 DATA 0, O* O, 30, 30- 49. 61. 61,
Q, Q, 0, 60, 60. 198. 246, 246,
63 f 49, 49, 63, 14, 14.
2, g
i,
254, 198, 198, 254, 56,
56,
32. 0
590
DATA 0. 0. 0, 15* 15. 49,
49,
55,
0, 0, 0 f 240, 249. 198.
198,
222,
55, 63, 49, 49, 63, 112
, 96.
64,
222, 254, 198, 190, 254
, 7,
3 f 1
600
DA f A 255. 255. 255, 207,
207,
255, 255,
240, 248, 252, 63 , 63,
252.
248. 240
1QOQ REM
101"' REM drah,tower-.routine
1020 CIRCLE INK OS 12, 167, 7
1030 INK G i PLOT 16. 158 * DRAW 7, O
s DRAW G, -158 - DRAW -23. 0 - DRAW 0. 23
t DRAW 23, O
1040 PLOT 255. 23 - DRAW 0, -23
1050 FOR I * 23672 TO 23674
= REM init-time.caunt
1060 POKE I , 0
1070 NEXT I
1080 RETURN
2000 REM
201O REM trap-Dec k
2020 PLOT 24. i 21-ng)*8+4
; DRAW INK 2; ID-3)*8-1, 0
2030 FOR I = (ID+(D > ID;> TO u STEP -1
2050 PRINT AT H, I * " frl-i ft A SHfi &*"
* prinf at h+i, i; tp £Laa c £ae
2060 BEEP .05. <36+1*
2070 NEX1 I
2090 FOR J = RH TO 18
2100 PRINT AT J, O; " A *"
? PRINT AT J + l, 05 M ** M
2110 PRINT AT J + i, 05 “ S8H A &"
i PRINT AT J+2, 0 3 >p klift C G_E6 D"
2120 BEEP .05, <24+J(
2130 NEXT 0
21*i< RETURN
8O00 REM
801 1 REM ftiain^looe
8020 BORDER 6 - PAPER 6 s INK 0 = OVER O * FLASH O
s CLS
8030 RESTORE * BO SUB 500
= REM de+ire A UEBr^graphicor*ship
gfi4, .* SO SOB 1000 i REM draw-.tower
53
3050 LET S = 50 * LET n ^ 20 * LEI D = 5
- LEI &h = O
; LET ng = * I NT i END *17) +2
= LEI Tr - sn
3060 LET OH = H * LET GD - D
3070 LET k* = INk.EYs
8080 LET H ^ H + (H < 19)-(k* = **S§* AND H i >* U 5
s LET 1H = INT H
8090 LET D - P+(k* = "d" AND H 19)*1,5-<D 3) * - 5
? LET ID = 1NT b
Si00 IF k* < > M d'* THEN BEEP -0125, -24
8!10 IF D > 30 THEN LET D ^ 50
Bl20 IF — G THEN GO TO 8570
SI 50 LEV = O
SI4o PHINT AE OH, DO;
* PRINT AT Oh++l, OD; " * V'
6150 PRINT AT H, D; 11 E CLEB F "
* PRINT AT H+i, Ds * Jijaa S kHB H"
6160 GD TO 6200
8170 LET ?h = l
8180 F^INT AT DH, DD;
s PRINT at DH+1- od; "
8190 PRINT AT H, Di " b.fLB A £J±& B"
i PRINT AT H+l, D? m C Qftfr D ,r
8200 IF D = 30 THEN PRINT AT 21, Ol
fh YOU j.ESCAPED + IN _ " ; ; GO TO 8370
8210 IF fr = O AND RND . ,9 OR H > 19
THEN SO TO 8060
8220 IF 4r = I THEN GO TG 8270
8230 LET ng = INT < INT ( RND *2)+H>-l
- LET ng = ng-lng > 18)
8240 IF ng < 2 THEN LET ng = 2
8250 LET get* * (ng > og)-(ng < og >
8260 LET T r — 1
8270 IF ng - og THEN GO TO 8310
8280 PRINT AT og, 0 - '* * * 14 s LET og - og+qm
8290 PRINT AT og, OS INK 2; w iaH B I iaRB J•»
8300 GO TO 8060
§310 PLOT 24 r (21-ng>»B+4 ± DRAW INK 2; 214, O
s BEEP * 2, 20
6320 PLOT DOER 1; 24, 42i-ng/*U+4
* DRAW INK 2; OVER 1; 214, 0 * BEEP , 1, O
6330 LET RH = <IH+(H > 1H))
s IF ng < > RH AND nq <> RH+i OR RH 7 19
THEN LET Tr = O = GO TO B060
8340 GO SUB 2000
6350 PRINT AT 21, OJ ,J YOU * LASTED*" ;
8370 LET T = INT f((65536* PEEK 23674+256*
PEEK 23673+ PEEk 23672> 7(50460) )* LOO) 100
8380 PRINT T; \M I NOTES 11
8390 ZF INKEV* = ,J ^ ,f OF INKEY* = “d”
THEN GO TO 8390
8400 IF INKEY* = M " THEN GO TO 8400
8410 CL 3 ; GO TO 8040
54
Lunar Lander
Copyright (c) Clifford Ramshaw
DESCRIPTION
You are the pilot of a remote-control space capsule
to be landed on the rough moon surface.
Every time you land unsuccessfully* you will destroy
the capsule and also make the landing site impossible to
be used again. You have to use another landing site and
try again with another capsule.
On successful landing a flag will be raised to
signify your claim of territory.
The capsule has a constant momentum build up moving
towards the right. At the same time, it is dragged down
by the moon gravity.
GOOD LUCK !I
HOW TO RUN THE PROGRAM
To start the program, type RUN (ENTER).
Use *5' to move to the left, * 7 * to increase your
height.
The space capsule will be moving constantly forwards
and at the same time be dragged down by the moon gravity.
You need to land with the two legs of your space
capsule exactly on the BLUE CYAN land site to be
successful .
PROGRAM STRUCTURE
The program uses the PLOT and DRAW facilities to
RANDOMLY draw the landscape for each game.
Special USER DEFINED GRAPHIC CHARACTERS are used to
draw the space capsule.
The crashing test of the capsule is based on colour
attribute testing.
The structure of the program is as follows;
INITIALISATION
SET USER DEFINED GRAPHIC CHARACTERS
11: SET LANDING FLAG TO 0
GOTO MAIN LOOP
55
main loop
SET SCREEN CONTROL VARIABLES
DRAW LANDSCAPE AND LANDING SITE
INITIALISE CAPSULE POSITION
Lis STORE OLD POSITION
CALCULATE NEW POSITION
blank old shape, draw new shape
IF CRASH
draw explosion ( G05UB 2000 )
generate sound
goto El?
IF NOT LANDED
goto LI;
FLASH BORDER * DRAW FLAG, GENERATE SOUND TONE
Eli PAUSE
GOTO II:
SPECIAL NOTES
The timing between blanking and drawing of capsule
has to be short in order that the capsule will not be
flashing.
The paper colour of the display is WHITE (7) and the
ink colour of display is BLACK (0)*
Crash testing of the capsule is based on colour
attributes; for landscape* the attributes are INK RED (2)
PAPER WHITE (7); for landing site* INK BLUE (1) PAPER
CYAN (5),
Thus* for perfect landing of two legs of the capsule*
the correct testing will be (41+41) on attributes of new
positions for the two bottom legs.
So, iT you want to change the colour attribute of the
landscape or the landing site or the background* then you
will need to adjust the testing value in line 8100 &
8150,
56
LUNAR LANDER
100
REM LUNAR
no
REM Lunar,Lander
120
RESTORE
s A FOR I = 1 TO 16
5 REM
initiali*e*GRAPHlC
130
LET S =
OSR ( CHR* (144+1-1))
140
FOR J =
1 TO 8
150
READ g
= POKE (S+J-l), g
160
NEXT J
170
NEXT I
180
DATA O,
O, 1, 1, 7, 7, 31,
25,
0, 0,
128, 128, 224, 224,
248, 152,
53, 107, 127, 243, 96, 96
, 192, 192
*
172,
214, 254, 207, 6, 6,
3, 3
190
DATA 1,
i fl Ip Ip Ip Ip Ip I
t
224,
176, 140, 134, 129,
135, 140,
176
Ip 1,
7, 1, 7, 7, 31, 25,
224,
120, 224, 128, 224,
224, 248,
152
200
DATA 0,
0, 0, 4, 5, 15, 6,
15,
0. O,
O, O, 96, 192, 224,
248,
27, 7
, 3, 6, Q, 0, O, 0,
120, 1 AS, 112, 32, 0, 0, O, O
210 DATA 160, 67, 30, 60, 24, 49, 96, 97,
4, 154, 244, 124, 6, 4, 4, 6,
194, 96, 32, 36, 104, 120, 79. 193,
130, 14, 12, 36, 124, 70, 195, 2
220 LET Ld = 0
230 SO TO 8000
1000 REN
1010 REM draw A base A and*landshape
1020 LET hx = INT < RND *21>
s IF bx < 11 THEN GO TO 1020
1030 LET Lt * bx*8 * LET rt = <bx+4)*B
1040 PRINT AT 21, bx? " QRtt SHI
s PRINT AT 21, bx+l; PAPER 55 INK 1
; " SR A SHI 6 LNU GHfl S U I 6 THU Jt
i PRINT AT 21, bx+3; " GRfi mi S'*
1050 LET di = ’-I s SO SUB 1500
* REM draw*lHt iO-f * t andsh ape
1060 LET di s 1 i GO SUB 1500
* REM draw A riqht j,Df 4 landshape
1070 RETURN
1500 REM
1510 REM draWilandshape
1520 REM input^di
1530 LET Ly - B+(di - 11*16
1540 LET Lx = C(rt+24)* <di * l))+(Lt*(di = -1)J
1550 LET up = 255-(di = -|)*255
1560 IF di = 1 THEN PLOT rt, S
s DRAW INK 2', 24, 16
1570 PLDT Lx, Ly
I5BO LET a = RND
* LET ry = (<a < = ,6)-fa > -6M*
< INT ( RND *48)+1)
1590 LET rx = di*< INT i RND *16>+1>
57
1600 IF di*(U+rx) > up*di THEN LET rx = up-Lx
1610 IF Ly+ry > 144 OR Ly+ry < O
THEN LET ry = O-ry
1620 LET Lx = Lx+rx - LET Ly = Ly+ry
1630 DRAW INK 25 rx, ry
1640 IF Lx <> up THEN GO TO 1550
1650 RETURN
2000 REM
2010 REM Expios1on^routine
2020 PRINT AT H, X;
2030 FDR 3 = 1 TO 5
2040 PRINT AT H+l, X; « GflQ A &R & B '*
i PRINT AT H+2, X; M QHA C QRfl D"
2050 BEEP .05. -f RND *49)
2060 FOR I = 1 TO 10 s NEXT I
2070 PRINT AT H+l , XI " SR A I fiRA J"
; PRINT AT H+2, X; " GAR K GRfl L ,T
2080 BEEP .05, -■( RND *48)
2090 FOR 1=1 TO IO * NEXT I
2100 PRINT AT H+t, X; " QBB M GHA N T|
- PRINT AT H+2, X; " GHfl O GRfl P"
2110 BEEP *05, “< RND *4S>
2120 FOR 1=1 TO 10 * NEXT I
2130 NEXT J
2140 FOR 1 = h+l TO 20
* PRINT AT i —1 , x;
; AT i, x; ” Gflfl D GBfl C IT ; AT i + i, k; M gbb
i NEXT i
2150 RETURN
BOOO REM
8010 REM MAlN*controioop
BO20 BORDER 3 = INK O * PAPER 7 * OVER O * FLASH O
s CL 5
8030 SO SUB lOOO c REM draw*land
0040 LET X = O * LET H = X
8050 LET OH = H * LET OX = X
8060 LET X = X+0.5*CX < 30)-t INKEY* = "5 M )
8070 LET H = H+0.5-< INKEY* = "7" )*(H > O)
8090 PRINT AT OH, OX 5
4 * PRINT AT OH+1, OX; *' **"
8090 PRINT AT H, X; M ££L0 A SifcLfi B*'
i PRINT AT H+l, X; " SR A C ORA D"
8100 LET cr = ATTR (H+2, X>+ ATTR (H+2, X+l>
8110 IF cr < SB OR cr = B2 DR cr » 112
THEN SO TO 8140
8120 GO SUB 2000 * REM explode
8130 BEEP *5, !7 ; BEEP ,5, 15 s BEEP -25, 13
* BEEP .25, 12 * BEEP .5, IO ± BEEP ,25, 13
s BEEP ,25, 12 * 60 TO 8210
8140 IF H >= 20 THEN GO TO 8120
8150 IF cr = 82 THEN LET Ld = 1 - GD TO 8170
8160* IF Ld ** O THEN GO TO BOSO
8170 FOR 1=1 TO 6 * PAUSE 25 * BORDER I * NEXT I
s BORDER 3
8180 PRINT AT 19, bx+I 5 " S Bfl E fi QB F'*
* PRINT AT 19, b« + l; " ERA 8 GRA H"
GR A
58
01 VO
BEEP
. 125
, 12
; BEEP
-25,
19 s PAUSE iO
s
BEEP
. 125,
12 *
BEEP
.25, 19 - PAUSE
10
£
BEEP
- 125,
12 i
BEEP
.25, 19 i PAUSE
ID
s
BEEP
- 125,
12 -
BEEF
.25, 19 - PAUSE
10
8200
BEEP
- 25,
12 =
BEEP
* 125,
14 i BEEP .125,
15
£
BEEP
- 125,
22 *
BEEP
-125, 22
*
BEEP
* 125,
15 i
BEEP
.125, 14
t
BEEP
- 125,
19 ±
BEEP
.125, 14
t
BEEP
• 25,
12
8210
FOR
I * 1
TO iOO = NEXT 1
* CLS * SO TO 220
'I
■#
59
Alien Blitz
Copyright (c) by Clifford Ramshaw
You are the sole defender of the space station* Suddenly
overhead you see them - 3 convoy of enemy aliens* They must
know of your power because they stay safely out of your
tractor beam reach.
What's this? - slowly one of them separates itself from the
rest of the fleet and swoops down on your position. Is it
possible that it's flapping its wings, or is that a space
illusion?
No time to worry about that - there are missiles falling.
Got to get them, those guys are fast; quick; get out the
tractor beam and pull him in. Got him. But wait - another
alien is detaching himself from the convoy * . .
Programming considerations:
This program is an arcade game for the Spectrum loosely
based on similar games to be found on video machines*
As such the main programming considerations are speed and
visual effects. Sound is only used when necessary, as it would
slow things down too much otherwise.
Therefore a minimum of work is to be done in each cycle, to
keep speed at a maximum. Only 3 variables are to be updated
each cycle:
coordinates of swooping alien
column position of player
The main loop is divided into two cycles, one for wings up
shap% and one for wings down shape. This allows the player and
alien to move faster as no decision needs to be made within
the main cycle as to the shape to be drawn.
Colour control codes are used within PRINT strings rather
than separately specifying INK 4, etc., to speed things as
well.
Program Structure;
IOO -340
Define shapes, draw convoy
500 - 630
650 - 790
1000 - 1440
First part of cycle
update all positions
Second part of cycle
Successful hits by player or alien
1500 - 1540 Destruction of enemy cenvoy
60
ALIEN BLITZ
IOO DATA 14, 31, 28, 24, 16, 16, 16, 16, 112, 248,
56, 24, B, 0, S, 8 s
REM Hings Jt restifig i shape Jt -A&
HO DATA 3, 15, 63, 127, 127, 127, 255, 227, 192,
240, 252, 254, 254, 254, 255, 199 s
REM top*hal-t *body*shape*- A CD
120 DATA 227, 227, 99, 99, 127, 63, 7, O, 199, 199,
198, 190, 254, 252, 224, O *
REM bottom A ha 1 T *bod y ^shape ^EF
130 DATA 240, 112, 56, 240, 124, 62, 255, 30, 15,
14, 20, 31, 62, 124, 255, 120, 7, 0, O, O, O,
O, 0, O, 224, O, O, 0, O, O, O, O *
REM wi r>gs ^up ^shape*H3HI J
140 DATA O, O, 0, 0, O, O, O, 7, O, O, O, O, O, 0,
O, 224, 30, 255, 62, 124, 248, 56, 112, 240,
120, 255, 124, 62, 31 f 28, 14, !5 £
REM wings*down A shape*— *KLMN
150 DATA 16, 16, 16, 16, 24, 2B, 31, 14, 8, 8, 8,
8, 24, 56, 248, 112 *
REM shape^of al1i ng *Hi ngs*—*08
160 DATA 0, 0, 12, 15, 31, 63, 127, 255, 24, 60,
60, 255, 255, 255, 231, 129, 0, 0, 48, 240,
248, 252, 254, 255 *
REM shape*o-f *laser A base*-QRS
170 DATA 66, 66, 30, 27, 15, 7, 3, 1, 66, 66, IDO,
216, 240, 224, 192, 128 =
REM shape*oT *enemy ^bul1ets*TU
100 FOR i = USR " ORA A" TO UBR 11 BRA A H +167
190 READ K * POKE i, *
200 NEXT i
210 BORDER 7 s PAPER 7 * INK 0 * OVER O * CLS
220 LET v ^ 21
230 LET s = 1
240 LET g = 5
250 LET x = 3+4ts
260 LET y = O
270 PRINT TAB xl
280 FOR i ^ 1 TO 5-s
290 PRINT "* E/LI mi 2 LRft C SRfl D**"i
300 NEXT i
310 PRINT * PRINT TAB x3
320 FOR 1 = 1 TO 5-s
330 PRINT " LXT SHI 4 &RA A £XT SHI 2 EBB E
gRfl F EXT SHI 4 BRA i
340 NEXT i
500 LET g = g+<g < 27>*( INKEY* = M c”)-(g > 1?*
t INKEY* = "z")
510 PRINT AT V, g; '* ^ EXT mi 2 BRA Q jjRfl R
BRA S/i AT y, Mi "****";
AT y+1, *; J, **** u
520 LET x = x+(y > 3)-(y < 4)+2*
SGN <g-x)*< RND > .51 * IF x > 28 THEN
LET x = G
61
530 LET y = y +1
540 PRINT AT y } k? " til SHI O £££ G til £HI 1
tifi C QMS D til SLtU O &afi H"; AT y+i, *;
" S-ELS I til SH I 1 GRfl E GRfl F ext SH I q
GRft J ■'
550 IF y - v-2 THEN GO TO 1400
560 IF RND > - 15 THEN GO TO 600
570 FOR i = y+2 TO v-1 * BEEP .02* v-i s
PRINT AT i, x + U AT i + t, x + !|
J1 I^R A T GRft LT i NEXT i
580 PRINT AT i, x + li
590 IF g = x OR g = x-1 THEN BO TO 1300
600 IF 1NKEY* <> "tin" THEN GO TO 650
610 LET m = 150 s IF g = x OR g = *-I THEN
LET m = 157-8*y
620 PLOT J9+8*g, 8 * DRAW 0, m * BEEF .1, 0 *
IF m < 150 THEN GO TO lDOO
630 DRAW INVERSE 1 ; 0 f 1 * DRAW INVERSE li 0* -m-I
640 REM secand^cycle
650 LET g = g+ <g < 27) * ( INKEY* = w c'*>“(g > 1>*
( INKEY* 5 = "z 11 )
660 PRINT AT v p g 3 ** EXT SH-1 2 SB B Q GRfl R
GB.B S^”i AT y, xi "_!
AT y+1 # *; M * Jt ** H
670 LET x = x+Cy > 3)-(y < 41+2*
SGN (g-x>*< RND > .5) * IF x > 20 THEN
LET x = 0
680 LET y = y+1
690 PRINT AT y t Ki " EXT SHI O SHfi K til 5JdI 1
SHA C Gflfl D EXT S±Ll O GRA L" i AT y+1, X?
" Gflft M EXT SMI 1 GRA £ GRA F
til SHI O GRA N"
700 IF y = v-2 THEN GO TO 1400
710 IF RND > .15 THEN GO TO 750
720 FOR i = y+2 TO v-1 * BEEP .01, v-i *
PRINT AT i, x + t! "**"S AT i + I, x + lS
41 GRA T GRA IT i NEXT i
730 PRINT AT i, x + 1 5
740 IF g = x OR g = x—1 THEN BO TO 1300
750 IF INFEY* <> "m” THEN GO TO 500
760 LET fn = 150 s IF g - x OR g * x-1 THEN
LET m = I57-8*y
770 PLOT 19+Blg, 8 * DRAW 0, m * BEEP .1,0*
IF m < 150 THEN GO TO lOOO
780 DRAW INVERSE l; 0, 1 * DRAW INVERSE 15 O, -ro-1
790 GO TO 500
1O0O FDR y ^ y+1 TO v-2
1005 BEEP .02, y/2
1010 PRINT AT y-t, xi " ****•'5 AT y, x?
" EXT SM1 2 GRA o ext ^HI 6 GRA C GRA D
EXT SHI 2 ERA P EXT SHI O"; AT y+i, x5
"* EftT J 6 GHA E GRA F EXT SHI Q*"
1015 NEXT y
1020 PRINT AT y-1, x;
1200 LET s = s+1
1210 PRINT AT y f x; "****"! AT y+1, xj
62
IF s < 5 THEN
"****" 5 AT o, o;
GO TO 250
1220 IF s = 5 THEN GO TO 1500
1300 PRINT AT v, g+l; " Q £08 Ft £06 S" ; OVER i;
AT v, x+l; '* GRH T £08 O'* 4- FDR * = 1 TO 11 s
BEEP *1, -IO * PRINT OVER 1; ftT V, qj
GRA Q GRA R ERA S" i BEEP -02, 4 s NEXT 1
1310 PAUSE 50
1320 CLS
1330 RUN 220
1400 PRINT AT y, *3 “*^^"5 AT y+I , x?
"**^"5 AT O, 05
1410 IF ABS tx-g> > 1 THEN GO TO 250
1420 PRINT AT v, g + I 5 " ££1 SJU 2 £HB Q £08 R
GRA S”! OVER l; AT y+l T x3 " Ea-T S_Hl 0
GRft G EXT g H ] 1 G R ft c G R ft D LX T SHI Q
GRA H" ; AT y+2, X3 “ EXT 5H1 I GRA I GRA E
pR A F GHA J M i FOR 1 = 1 TO II *
BEEP -1, -IQ * PRINT OVER 15 AT v, g5
" EXT SMI A G R ft Q GRA R GRft S" 4
BEEP .02, 4i NEXT i
1430 PAUSE 50
1440 RUN lOO
1500 PRINT AT 5, 0 3 "Congrat ul at ions*- 4 you 4 have
* ^ ^ * .destroyed ^th^^ent ire^enemy
1 ee t fl
1510 BEEP .3, 1 - BEEP .05, O s BEEP .05, s
BEEP .5, 9 4 BEEP .05, O s BEEP .05, -1 s
BEEP .6, I ; BEEP .5, 10
1520 PRINT FLASH l; PAPER 2J INF 7; AT 10, O;
"WATCH *OUT *- *HERE ^THEY ^COHE * AG AIN 11
1530 FOR i = 1 TO 3 s BEEP 1 f 20 4 BEEP .I, O 4
NEXT i
1540 RUN lOO
63
Spectrum Invaders
Copyright (c) by Beam Software
It's hard to believe, but the all-time favourite arcade
game, the one that started the whole concept of arcade games,
and is still one of the most popular around the world is
available right here on your Spectrum,
This version of Spectrum Invaders features
* 24 invaders moving from side to side
* animated Invaders - watch them move!
* shields to hide behind
* dangerous enemy bombs
* laser fire power
* continuous score update
* sound effects
* increasing difficulty with each wave
To play the program, use the M X" and "C 11 keys to move the
laser base left and right, and the "M ,r key to fire your
miss 11e,
It Is your responsibility to defend the planet, earthling!
Programing considerations:
One of the problems with trying to write a BASIC program
for this type of arcade game are the very high number of
variables required, together with the demands of fast action*
It would not be possible to write a BASIC program of this
type, keeping track of 27 pairs of variables (x,y coordinates
o£ 24 invaders, laser base, enemy bomb and laser blast) and
still have a reasonable arcade game. It would be doubly
difficult to have them animated as well, and to keep track of
which invader had been hit, for example*
This program makes use of two features of the Spectrum,
which together make this amazing program possible:
* Printing a very long string is not much
slower than printing a shorter string.
It is certainly much taster than printing
a number of strings.
* It Is possible to use the unique string slicing
facility on the Spectrum to assign part of a
string, ie one can say, for example:
LET a$ (2 TO 6) * "HELLO"
The core of the program therefore lies in two strings, and
the manipulation of these two strings, a$ and b$. the string
a$ is used to keep all 24 invaders, print them, etc. For all
intents and purposes, b$ is the same as a$, in that it will
64
always be the same length as a$, have as many invaders in it,
etc*, but b% contains the same Invaders in a slightly
different posture. By alternating rapidly between a$ and b$,
the invaders appear to move their arms in and out, move their
legs* and so on*
By printing a$ (and b$) in various positions, we can print
in one hit all the invaders, and automatically take care of
the undrawing problems (as the new printing will overwrite
the old positions}*
Should an invader get hit by a laser blast, the invader is
replaced by blanks within the string using the string slicing
technique described above* Regularly as well, the end of the
string is checked to see if contains all blanks (ie all
invaders in the bottom row have been killed). If that Is the
case, string slicing is used again to shorten the string to
its new maximum length.
This not only prevents any potential problems with printing
beyond the bottom of the screen, but give an immediate test
as to whether the laser base has been overrun* A small
by-product is that as the string gets smaller, it takes less
time to print and the game speeds up a little towards the
end ’
Program structure:
100 -160
Define graphic characters
200 -625 Initialisation
The main task is to build up a$ and b$
using subroutine at 9000 - 9030
1000 -1200 First part of main loop
a$ is printed, laser blast is updated,
laser base position unpdated tf required
enemy bomb position updated
2000 - 2999 Second part of main loop
same as first part but with b$
also new enemy bomb creation
3000 - 3530 Change of direction for invaders
a$ checked for possible slicing
5000 - 5220
6000 - 6530
8500 - 8550
Effect of laser blast hit
Effect of enemy bomb hit
End of game
65
INVADERS
100
DATA 0,
31,
63,
63, 123, 113, 225, 225, 0, 248
252,
252,
222,
142,
135,
135, 255, 127, 111,
111,
199,
192,
240,
240,
255, 254, 246, 246,
227,
3, 15, 15
110
DATA 7,
63,
127,
65,
193,
199, 255, 124, 224,
252,
254,
131,
131,
227,
254, 62, 124, 127,
51, 4B, 112, 90, 136, 249, 254, 204, 142, 26,
17, 31, 0, 0
120
DATA 31, 63,
63,
115,
113,
225,
225,
255,
240,
252, 252,
206,
142,
135,
135,
255,
127,
1U,
103, 103,
96,
48, 60
, 60,
254,
246
, 230
, 230
6, 12, 60,
60
130
DATA 7, 63,
127,
193,
193,
199,
127,
124,
224,
252, 254,
130,
131,
227,
255,
62,
127,
51,
113, 88, 136, 248, 0, 0, 62, 254, 204, 12, 14,
26, 17, 31
140 DATA 24, 24, 24, 24, 60, 126, 231, 231, 7* 31,
63, 60, 112, 112, 240, 240, 224, 248, 252, 60,
14, 14, 31, 3!
150 DATA 10, 26, 14, 14, 7, 3, i, O, 36, 44, 56, 56,
112, 96, 192, 12B
160 FOR i = USR "a" TO USR "a"+167 * READ x *
POKE i t H s NEXT i
200 BORDER 7 s PAPER 7 * INK O - CLS
210 PRINT AT O, O; "score"; AT O, 23; "li ves*^"
220 LET f - 2
230 LET sc — O
250 LET q - f * LET f = 4+i ? IF f - 11 THEN STOP
300 LET c* = "*************^^*
310 LET s = 144
320 BO SUB 9000
330 LET k* = a*+b*+c*
340 GO BUB 9000
350 LET 1* = a*+b*+c*
360 GO SUB 9000
370 LET m* = a$+bf+cf
390 So SUB 9000
390 LET nf ^ ^+bi+ct
400 LET a* = k*+l*+k*+l* ; LET a* = a*( TO 3431
410 LET b* = m*+n*+m*+n* - LET b* = b*C TO 343)
500 LET k* = " GRfi 4 SRft SHi 4 fi RQ 3
GRft 7 GELS SH 1 7***." *
LET 1* = " GRA SHI 6 GRfl SHi 6 GRA 3
GRA 6 ERA =
LET inf = N GRA 7 ERA 2* ERA 1
GRA SHi 4 * ^ " i LET n* = ""
510
PRINT
INK
4; AT 16, 2; k* ; k*;
k*3
k* ;
is;
1*5
1*;
n>*; m* ; m* ; mf
590
LET L
= 0
600
LET r
= O
i LET s = 10 J LET t
- 1
610
LET u
- 0
£ LET v = 0 s LET x ®
O ?
LET
y “
0
615
LET d
= 21
* LET e = 12
66
620 PRINT AT 20, 30; c*
625 LET Lx - 3
lOOO FDR p = r TO s STEP t
1010 BEEP .005, 1 ^ PRINT AT q, 05 cff TO p>| a* i
AT 20, l; "* gra Q
**^**** A R q P ^ 3 GRfl S*"
1020 IF u < q THEN GO TO 1050
1035 IF SCREEN* <u, v> <> M THEN GO SOB 5000
1040 IF u >= q THEN PRINT AT u, v? « £Rfi O m *
AT u+1, v;
1050 LET L = L+<L < 28)*f INKEY* = "c">-(L > 0>
*( INKEY* = "z*'>
1060 IF u > q-1 OR INKEY* <> "m" THEN GO TO 1100
1070 LET u — 20 s LET v = L + l
1100 IF d > 20 THEN GO TO 1200
1110 IF SCREEN* <d t e> <> N * w THEN GO SUB 6000
1115 IF SCREEN* <d, e+1) <> ,l * N THEN GO SUB 6000
1120 IF d < = 20 THEN PRINT AT d-l, e; INK 2
AT d, e; " ERA T ERA U* 1
1200 LET u = u-1
2010 PRINT AT q, 05 c* < TO p)| b*i AT 20, L!
"* B*--*****
fiRA R qpft 3 GRfl S^ u
2020 IF u < q THEN GO TO 2050
2035 IP SCREEN* <u, v) <> " THEN GO SUB 5000
2040 IF Li >— q THEN PRINT AT u, v? " SR ft Q"l
AT u+1, v! "
2050 LET L - L+(L < 2B) * < INKEY* = "c J, )-U_ > 0)
*( INKEY* = "z")
2060 IF u > q-1 OR INKEY* <> 11 m" THEN GO TO 2100
2070 LET u = 20 * LET v = L+l
2100 IF d <= 20 THEN GO TO 2130
2110 LET w = INT (6* RND > -
LET >:$ - a* C LEN a*-4*w-2) *
IF w* <> ” GRfl C" AND x* <> " ERA S" THEN
GO TO 2130
2120 LET d = q+l+ INT < LEN a*/32> =
4 let e = p— 4*w+20+t
2125 IF e « 31 THEN LET e = 30
2130 IF d = 20 THEN PRINT AT 20, e? " **"
2200 LET u = u-1
2210 LET d *= d +1
2999 NEXT p
3000 IF t = -I THEN GO TO 3500
3010 LET t = -1 * LET r = 9 * LET s - O
3020 60 TO 1000
3500 IP LEN a* > 55 THEN GO TO 3510
3505 IF a**23 TO ) = c* THEN GO TO 250
3510 IF a* < LEN a*-32 TO ) — c* THEN
LET a* = a*< TO LEN a*-96> ±
LET b* = b*C TD LEN a*>
3520 IF 32fq+ LEN a* > 609 THEN GO TO 0500
3525 LET r ^ O * LET s ^ 10 s LET t « 1
3530 PRINT AT q, 01 c* * LET q = q+1 * GO TO lOOO
67
5000 IF ATTR fu, v> =60 THEN GO TO 5100
5005 IF ATTR (u, = 59 THEN GO TO 6000
5010 LET h = v—p+32*(u-q-1 )
5015 BEEP -05, B
5020 IF h >= O THEN GO SUB 5200
5030 LET h * h+32 ? IF h < LEN a* THEN GO SUB 5200
5040 LET h = h+32 = IF h < LEN a$ THEN GO SUB 5200
5050 LET h = 4- INT <h/96>
5060 LET sc = sc+10O*h s PRINT AT 0, hi sc
5100 REN create A an*expiosion
5110 PRINT INK 61 AT U f vi " GRB B ERA A M ;
AT u+1, v 9 11 GRB S GRfl R M ± BEEP -05, 10 5
PRINT AT \JL f vi i AT u + i, vi
5120 LET u = O
5130 RETURN
5200 IF h = 0 THEN LET h = 1
5205 LET a*(h TO h+2) = * ***”
5210 LET b*(h TO h+ 2 ) = ,, *** 1,
5220 RETURN
6000 REM 1 ook * where *al i en *bul 1 et *hi 1
6005 IF d = 20 THEN GO TO 6019
6010 PRINT AT d-1, “**“s INK 2i AT d, ei
" Gfifl A Gflfl B“ t BEEP .05* -10 t
PRINT AT d, &5 ***"
6012 IF <v = e OR v = e+1) AND d = u THEN
PRINT AT u* v; f AT u+1, vi ,l *'* *
LET a = O
6015 LET d — 21 - RETURN
6020 PRINT AT d™l , e; ,, ** n ; INK 2 5 AT d* ei
” aaa a b " * beep . 05 , 10 ±
PRINT AT d, @| '* * * 11
6030 FOR k = 1 TO 10 s PRINT OVER 1? AT 21, Li
** QRfl R EBB 3 QBB S n * BEEP -1,0* NEXT k
6040 LET LI = Li-1
6050 PRINT AT O, 29; " ***“; AT O, 29;
" rtAA,, < TO Li)
6060 IF Li = O THEN GO TO 8510
6500 REM missi I es*hitbrother
6510 IF d <= 20 THEN PRINT INK 6 i AT d, e;
" [LED B GRA A M i AT d+1, ei " GRA S GRA R‘*
BEEP . 05, 10 * PRINT AT d, 0 i
AT d+1, ei
6520 LET u = O s LET d - 21
6530 RETURN
8500 PRINT AT q, 01 ct; a*
8510 PRINT AT 5, O* ,f * A The *al i er >5 *have ^overrun
.you." * PRINT " ^All^is^Iost- "
8520 INPUT "Do*.you .-.want *to*try *agai n? w ; nt
8530 IF LEW n* = O THEN GO TO 9520
9540 IF n*(l) - "y" OR n* (1 > = 11 V" THEN RUN 200
8550 STOP
9000 LET a$ = CHR* (s> + CHR* (s+1 > + ,r ^ *2* *
LET a* = dPaPa*+af+al+a« + L i444i4i M
9010 LET b* = CHR* <s+2)+ CHR* <s+3)+"i
LET b* = b*+b*+b*+b*+b*+b*+" *„****/■
9020 LET s = s+4
9030 RETURN
68
Meteor Storm
Copyright (c) by Beam Software
METEOR STORM places you at the controls of a space craft
hurtling through the asteroid belt. On your display you see
the pleasant view of the solar system as seen from mid space*
Tn the distance, you can see Saturn with its rings, and
beyond that the many stars of nearby galaxies.
Suddenly command control warns you of a METEOR STORM!
Before your very eyes, you see a meteor growing in size as it
heads directly for your ship I To confirm the desparate
situation, your on-board radar shows the approach of the
asteroid.
METEOR STORM is 3-Dimensional computer gaming at Its most
exciting.
Running the program:
After you press (RUN) CENTER), you will see the familiar
console display come to life.
A cross hair in the middle of the screen marks the
direction your laser beam is aimed at. To manipulate the
beam, use the following controls:
"I" and "P M to move left or right
,T W" and to move up and down
"O'* to fire
Note that as with most BASIC programs, only one key can be
pressed at a time-
The cross hair control features full wrap-around - In other
words, going too far to the right will bring you to the Left
of th| screen, and so on.
You can fire at any time, but missing the asteroid results
only in the dull sound of the laser hurtling into the void, A
hit on any part of the asteroid however will see it being
thrown back beyond danger.
As you penetrate deeper into the METEOR STORM, they start
coming at you faster and faster. Bow many can you shoot with
only three lives?
Programming considerations:
This program makes extensive use of the OVER facility of
the Spectrum, as well as demonstrating the re-useability of
the user defined graphics characters.
69
At the beginning of the program, user defined graphics are
used to draw the shape of the spaceship console, the radar
display ship and the planet Saturn. This is the only time in
the entire program they are drawn! In fact, immediately
afterwards, the user defined graphics characters which made
up the picture are re-used to define the asteroid shapes!
This works because the display on the screen is not
dependent on those characters - once anything is written onto
the screen memory, by whatever means, it will stay there
until something overwrites it.
The immense advantage of the OVER facility now becomes
obvious. By keeping very clear controls on what has been
written, and making sure to erase it only by overwriting
exactly the same thing at the same spot again, we can keep
all the original information on the screen in its original
format.
(The way OVER works is that by writing the same thing OVER
a second time, it will become erased, leaving whatever was
underneath it originally intact - try it!)
Structure of the program:
100 - 200 Definition of characters, as follows:
Round corners
Spaceship as seen on radar
Saturn
Shapes for small meteors 1 (ABCD)
Shapes for small meteors II (EFG)
Shapes for meteors III (HIJK)
Shapes for meteors IV (LM)
Shape for explosion I (NOP)
Shape for explosion II (QRS)
200 -*340 Set up console screen
400 - 590 Define characters again and
initialisation, FLash message
The main time consuming task is taken
up with defining b£, an array with random
meteor shape used in final collision
explosion display.
Useful variables are:
X, y
position of crosshair
ox, oy
old position of crosshair
LI
number of lives
ms
meteor stage (range 0 - 9)
di
difficulty level
mx, my
position of meteor
V
ink colour under crosshair
900 - UOO Main loop
70
1200 - 1500
3000 - 3100
4000 - 4880
5000 - end
Test keyboard, move crosshair
Laser blast
Subroutine to update radar
Subroutines to print meteor in various
sizes
Routine to handle collision with meteor
Special notes:
The extensive use of DATA statements that this program
makes is very expensive cm memory, and this program would not
fit within a 16K Spectrum if we did not take special steps to
reduce the memory usage of this program.
For example, each number in a DATA statement is stored in
memory not only as the characters you type in but ALSO as a
6-byte sequence which is in a format suitable for the
Spectrum ROM to operate* In other words, a DATA string with
32 numbers takes up 6 bytes for the line number, etc
information, about 100 bytes for the characters typed in, and
a further 200 bytes because of the way the computer stores
this information.
This 6 byte cost of entering numbers is present in all
BASIC statements, not just DATA statements. You will
therefore note that this program defines the two most
commonly used numbers, 0 and 1, right at the beginning as
variables, and these are used throughout tir£ program*
The saving in memory is enormous - each number now only
requires two bytes, including the comma separating numbers.
4
71
METEOR
90 LET 2=0* LET u - 1
1O0 DATA 255* 248, 224, 192, 192, 12B, 128, 128,
255, 31, 7 * 3, 3, u, u, u, 128, 128, 120,
192, 192, 224, 248, 255, n, u, u, 3, 3, 7, 31,
255
1 io
DATA
Zl
z, 128, 192,
231,
255, 255, 255, z, z.
2 t
Z)
192, 240,
60.
255,
li, 3, 7. 14, z , z,
z f
Z)
240, 224,
128
* Z(
z, z, z, z
120
DATA
Z|
3, 7, 15,
15,
31,
31, 127, z, 192, 240,
24B, 248, 254, 253, 249, 127,
31, 7, 3, z, 195, 4, 60, 248,
220,
248,
192, 115,
240, 192, z
130
DATA z, z, u, 3,
31, 63, 14, z,
30, 28, 12, z,
7, 7, 7, 2, z j
4, 14, 31, 63,
z, z, z
4, 6
63,
, 15, 31,
63, 31, 30,
140
DATA 31, 63, 31,
128, 192, 224,
31, 15, 6, z,
224, 224, 224,
z, z,
224,
Z, 2 # Z,
192, z, z.
2, z
150 DATA 3, 23, 55, 63, 127, 127, 127, 127, 128,
224, 240, 240, 224, 24B, 248, 252, 127, 63,
63, 127, 63, 31, 11, z, 252, 252, 24B, 224,
240, 224, 128, z
160 DATA 63, 127, 255, 127, 255, 255, 127, 63, 252,
248, 252, 254, 254, 24B, 248, 252
170 DATA 195, 153, 60, 102, 102, 60, 153, 195, 195,
99, 39, 60, 60, 180, 231, 231, 128, 60, 230,
255, 91, 200, 221, 119
1BO DATA 38, 62, 246, 254, 108, 71, 227, 62, 115,
55, 246, 100, 28, IBB, 246, 9V, 221, 1 IB,
103, 238, 184, 115, 255, 128
200 BORDER 5 * INK 5 i PAPER 6 * CLS
210 RESTORE 100
220 FOR i = USR “a 11 TO USR "m"-u
230 READ x t POKE i, x * NEXT i
240 DIM s < 10)
PR INT
AT z.
>
GRfl
A";
AT ;
31
T
■■ GRA B"
5
AT IB, z
■
GRfl c";
AT
10,
31;
41
GRfl
D"
PRINT
" GRft SHI
8 GRft SHI
8 GRfl SHI
8 GRA SHI
RRfl
SH I
8
GRft
SH t
a
GRfl
SHI
8
GRA
SH t
0
uaa
SHI
S
aaa
SHI
8
GRA
SH 1
0
GRA
SH I
8
GRft
SHI
e
GRA
SHJ
a
oaa
mi
B
GRA
sp I
8
GRfl
SHI
a
GRfl
5 H I
8
GRfl
SH I
8
GRfl
SH I
8
aae
mi
e
aaa
iiiU
8
GRA
8
GRA
am
8
GRfl
SH I
8
GRft
SH I
e
GRA
SMI
8
GRA
SHI
a
aaa
SH 1
8
GRA
SHI
8
GRA
SH I
8
GRA
SH i
8"
= PRINT
" sma i
g H ,1
8 GRfl A
A ^ ^ GRf
\ B GRB
SH I
8
GRA
SH l
8
GRfl
SHI
0
GRA
SHI
a
GRA
A
** **
fififl B
GRA
SH I B
5 H I
a
GRfl
C . .
uILlj D !
m B
SH I
8
G R ft
£Hi
8
GRfl
SHI
8
GRA
SHI
8
GRfl
C
BRfl D GRA SH 1 0"
72
320 PRINT INK z; AT 20, 2; “ URB E ORB F";
AT 21, 2; " ERA G QRB H" ? AT 21, 23 5
! TivP5 A 3 H
330 FOR i - Li TO 20 = PRINT INK 2l
AT u+16* RND , li+29* RND ; ". M * NEXT i
340 PRINT INK 35 AT 6, 10; *’ GRfl I ORB J'S
AT 7, 105 " mB K £HB L"
400 FOR i = USR "a" TO USR H t"-u
410 READ * = POKE i, x * NEXT i
420 PRINT OVER u? FLASH u; INK 2i AT iO, 4;
"PREPARE *FOR *FL IGHT * INTO' 4 ; AT II, 10 i
"METEOR*STORM°
430 LET b* = HH s FOR j = u TO 17
435 BEEP *05, z
440 LET a* = *'*"
450 FOR i = u TO 15
460 IF RND > .6 THEN
LET a* = a*+ CHR* <144+12* RND }
470 LET a$ = a*+"** u *
475 BEEP ,005, iO
4BO NEXT i
490 LET b* = b*+a*C TO 29>+"* M ± NEXT j
500 PRINT OVER Ui FLASH zI AT 10, 45
"PREPARE*FOR*FLIGHT*INTO"5 AT 11, 105
"ME TEOR * STORM M
520 LET ok * 9 * LET oy - 15 = LET ov = 5
530 LET x - 9 * LET y * 15 s LET v = 7
540 INK z i PRINT AT x, y5 ,, + "
550 LET Li * 3 i LET di = u s LET nm *= z
560 LET ms - z * LET nm = nm+u
580 LET m* = u+ RND *17 ± LET my = u+ RND *29
590 LET mi « u
900 LET a* = INKEY*
910 LET ms = ms+di/7+nm/50
920 IF INT ms — 9 THEN GO TO 5000
930 GO SUB 3000
940 GO SUB 4000+100* INT ms
950 LET v4 = ATTR Cx, y>~8* INT I ATTR <x, yl /0) *
IF w <> O THEN LET v = w
960 IF a* = " H OR a* = "O" THEN GO TO 1070
lOOO LET y = oy+Ca* = "p">-(** = "i">
1010 IF y < u THEN LET y = 30
1020 IF y > 30 THEN LET y = u
1030 LET x = ox+la* = = "n ">
1040 IF x < a THEN LET K = 17
1050 IF x >17 THEN LET x = u
1060 LET v = ATTR Cx, y)-8* INT C ATTR Cx, y»/B)
1070 PRINT OVER 05 INK ovS AT ox, oy5 " + "; INK z;
AT x, y;
1090 LET ox — x = LET oy - y * LET ov = v
IlOO IF a* <> "O" THEN GO TO 900
1200 FOR i ^ u TO 6 ; BEEP ili/lOO, lO/i * NEXT 1
1250 IF v <-> u THEN GD TO 900
1260 LET x1 = x-u s IF xl < z THEN LET xl = z
1270 LET yl * y-u ± IF yl < z THEN LET yl = 2
1275 LET *2 = x+u s IF x2 > IS THEN LET x2 - 18
?3
1280 OVER ti f FOR i — u TD 10 * BEEP . 03 t 3 s
PRINT AT k, y; " Gflfl N" s BEEP .01, u ±
PRINT AT xl f y!3 " tifcLB O ERA P SRft 0 ,T |
AT m, yli " QMB Q SRB N 0°; AT x2, yi ;
« ERA R GFtA B EBfi R" i NEXT i - OVER 2
1290 DIM s(10> i LET mi = 2
1300 FOR i = INT ms TO z STEP ~u
1310 LET ms ^ i ^ 80 SUB 4000+1DO*i ? GO SUB 3000
1320 NEXT i
1340 DIM stlO)
1360 LET ov = z * LET v - z
1370 PRINT INK 23 OVER z| AT 20, 23; nm+Li-3;
AT 20, 263 "shot"
1380 PRINT OVER U3 INK 3; AT 6, 105 "**"•
AT 7, 105 "**"
1500 GO TO 560
3000 IF I NT ms < 4 THEN PRINT INK u3 AT 20, 14-ms3
■* * I^RA B^"
3010 IF INT ms = ^ THEN PRINT INK u3 AT 20, 9;
M „ GAP B * * "
3020 IF INT ms > 4 AND INT ms < B THEN PRINT INK u ;
AT 20, IB-2# INT msl " QBB B** M
3030 IF INT ms = 8 THEN PRINT INK ul AT 20, 4;
" gra Bii"
3040 RETURN
4000 IF 5(1) ” u THEN RETURN
4010 PRINT OVER u; INK mi 5 AT mx, my; " QHB A"
4020 LET 5(11 = y
4030 RETURN
4100 IF s (2) = ll THEN RETURN
4110 PRINT OVER u; INK mi 3 AT mu, my; " SRB
4120 LET s ( 2) = u
4130 RETURN
4200 IF s<3> «= u THEN RETURN
4210 PRINT OVER u 5 INK mi; AT m*, my;
'* Gflfl B gra p"
4220 LET s(3) — u
4230 RETURN
4300 IF s(4> = u THEN RETURN
4310 LET mvr 4 = mx+u
4320 PRINT OVER u? INK mil AT mx, my;
" ERA B ERA F" ; AT mx4, my 5 " ERft D"
4330 LET s 14 > - u
4340 RETURN
4400 IF s(5> = u THEN RETURN
4410 PRINT OVER ul INK mil AT mx, my* rt C #1 ;
AT mx4, my I ** ERA E“
4420 LET s<5> = u
4430 RETURN
4500 IF s(6) - y THEN RETURN
4510 PRINT OVER U3 INK mil AT mx. my I
« 6RA C GRfl F"S AT mx4, my I " SHB E S£L£ G"
4520 LET s <6 > = u
4530 RETURN
4600 IF S(7‘) = u THEN RETURN
4610 PRINT OVER u| INK mi; AT mx, my;
74
" GRA H GRA I»i AT mx4 t my; " ERA J GRfl K’*
4620 LET 5(7) - u
4630 RETURN
4700 IF s(B> = u THEN RETURN
4710 LET mx2 =
4720 LET my6 - my+2 s IF my6 > 31 THEN LET my6 = 31
4730 LET mx5 - mx+2 s IF mxS > 10 THEN LET mx5 = IS
4740 LET my3 = my-Li
4750 PRINT OVER u! INK mi; AT mx2, my; M GRA C GRfl F”
; AT mu, my3; " GRfl C GRfl SHI 0 ERA 5HI 8*"
; AT mx, my65 " GRB F ; AT mx4 f my3|
* f GRfl E GRA SHI 0 fipfl SHI 8"; AT mx4, my6;
" GRA 6"5 AT mx5, my J w GRA E GRA G“
4760
LET s(8>
- il
4770
RETURN
4800
IF s<9>
-
u THEN
RETURN
4B10
LET mx1
=
mx -2 *
IF
mx 1 <
z THEN LET mx1 = z
4020
LET my2
-
my-2 *
IF
my <
z THEN LET my - z
4030
LET my7
=
my+3 s
IF
my 7 >
31 THEN
LET
my7 *
31
4840
LET mx6
=
mx +3 i
IF
mx 6 >
10 THEN
LET
mx6 =
18
4050
LET mx6
mx+3 s
IF
mx 6 >
18 THEN
LET
mx6 ”
10
4060
PRINT OVER ui INK mi
; AT
mxl, my;
" GRA C GRA F” 5 AT mx2, my3;
" GRA H GRA SHI e GRA SHI B" 5 AT mx2, my6;
" GRA 1"; AT mx , my2i " GRA C"; AT mx, my3;
" GRfl SHI 8 G R p SR 1 0 GRA SHI 0" ;
AT mx , my 6;
" GRA SHI B“i AT mx, my7| * GRA F" j
AT mx4, my2i H E"; AT mx4, my3;
M GRA SH [ B Igpfl SH I 8 ERA SH 1 0*' ;
AT (dm 4, my6;
" am 0" 5 AT m«4, my7 ; " G";
AT mx5, my3i " GRA J GRA £HJ 0 £Rfi £Hi B" »
AT ntKS, my6; " GRA K"; AT mx6, myi
" GRA E GRA 6 f *
4870 LET s<?> = u
4880 RETURN
5000 FOR i - z TO 16
5010 PRINT OVER u; FLASH u; AT i+u, u;
b*<30*i+u TO 30*i+30)
5020 NEXT i
5030 PRINT FLASH u? OVER u; AT 20, I I
AT 21, 1; "^i*******^*^^"
5400 DIM s<10»
5500 FDR i = u TO 40 - BEEP RND /ID, 10* RND -5
5510 IF i >31 THEN GO SUB 0000-100*3
5520 NEXT i
5530 LET ov = 4 t LET v ^ 4
6000 FOR i = z TO 16
6010 PRINT OVER u; INK 2; FLASH z; fit i+l, M
b* (30*1+1 TO 30*i+30>
6020 NEXT i
6030 PRINT FLASH zi INK 5I OVER 13 AT 20, 1;
"* am o***„****„*
am at 21, is *** km am 0
75
0
EXT SHI 5.* EXT S H 1
6035 PRINT OVER ui AT 20, 4? " QRQ B"
6040 LET Li = Li -u
6050 PRINT OVER z; INK z; AT 21, 2V; Li
6060 IF Li - z THEN STOP
6070 DItt s(10>
6200 GO TO 560
4
lb
Eliminator
Copyright (c) by Beam Software
You are the protector and defender of the humanoids on the
surface of the planetoid* Your task is to ELIMINATE the
invaders *
You must prevent at ail costs their attempts to kidnap the
humanoids under your care* Their survival and the survival of
their planetoid depends on you*
The planetoid you are guarding Is only a small one, and It
is possible to fly right around it very quickly, but you can
travel only in one direction.
The enemy kidnappers have released a heat-seeking missile
against you, in order to distract your attention away from
the real issue* Can you perform evasive action, shoot down
the invaders and protect the humanoids?
Playing the game:
You are in control of the space craft in the centre of the
screen* Your forward momentum does not allow you any
flexibility in moving sideways*
Your only controls are therefore up and down, using the ’’V*
and ft X" keys.
You have at your disposal a laser blaster, controlled by
pressing the "P" key, which will destroy the heat seeking
missiles and kidnapping invaders, but it only brings
temporary relief. As soon as you shoot one, the next one
appears*
Your^raft can sustain some damage, but after three hits,
your craft is no longer operative.
Programming considerations:
There are no available commands in BASIC in order to simulate
the movement of the spacecraft against the surface of the
planet*
Even if there were suitable commands (such as SCREEN!; note
that this cannot be used as it does not recognise user
defined graphics!!), horizontal scrolling of the screen would
he painfully slow*
The only solution available, and the one that is used here,
is to have the horizontal scrolling routine written in
machine language. You will find this routine, 36 bytes long,
7 7
in the DATA statement at line 3000,
What this routine does is to take each line of the screen*
and wrap It around- ie* the character that was at 0*1 will go
to 0,0* the character that was at 0*0 will go to 0,31, and so
on *
The routine then does the same thing for the attributes* so
that the colour associated with each shape moves with it*
This machine language routine is fully relocatable - in
other words, you don't need to know anything about machine
language to use it- Simply use a program similar to that in
lines 140 and 150. Because this routine is fully relocatable,
you can specify any address that will not be overwritten as
the address it should be POKEd into.
You may be interested in trying to adapt this routine for
other programs. You can be sure that Melbourne House is
always keen to see any exciting programs you may develop.
The rest of the program is mainly taken up with keeping
track of the variables relating to the spaceship (sx,sy),
alien (ax,ay) and bomb (bx,by). Because of the continuous
scrolling this is quite time consuming, but essential.
Structure of the program;
100 - 150
Initialise variables, character set
160 - 360
1000 - 1020
5000 - 5360
4
7000 - 7330
8500 - 8760
Draw landscape* fit in men on towers
Draw ship* alien, bomb
Main loop
Check for ship movement
Make alien seek humanoids
Make bomb head for ship
Fire laser if key pressed
Check for possible collisions
Kidnap loop
Check If any humans left, etc
Damage to ship routine
including end of program
78
ELIMINATOR
lOO RESTORE 2000
110 FOR i = USR "a" TO USR "k'*-!
120 READ x s POKE i, *
130 NEXT i
140 RESTORE 3000 - CLEAR 32500
150 FOR i = 32500 TO 32535 ? READ x = POKE i, x
* NEXT i
160 BORDER 1 * PAPER I - INK 0 * CLS
170 PLOT 0, 8
180 LET y = 8
190 LET p = *1
200 FOR j =* 1 TO 3
210 LET a - 3+ INT C7* RND )
220 GO SUB 8100
230 DRAW 4, 15-y ; DRAW 9, O
240 LET y = 15
250 LET p = p+a+1
260 FDR k = 1 TO INT <4* RND >+1 i PRINT INK 5i
OVER i; AT 20—k, pi M &RB C" *
NEXT k * PRINT INK 3i AT 2G-k, pi
" aafl B" 3 AT 19-k, P5 M EBB
270 NEXT j
2B0 LET a = 30-p
2VO GO SUB BlOO
300 DRAW 11, B-y
310 LET sx = 3 i LET sy = 10
320 LET ax = INT U5* RND 3 * LET ay = 26
330 LET bx - INT 1 RND *15) ± LET by = 30 s
IF fax - ax THEN GO TO 330
340 LET t = O
350 LET e = O s LET h = 3
360 LET dm =* O * LET sc = O
lOOO PRINT INK li AT sx, sy; SiLLD F
gag g bra h bra i 11
ICIO PRINT INK 4; AT ax, ay; " * fiflfl D GRA E'*
1020 PRINT INK 2i AT bx, by; "* £H£ J"
2000*. DATA 1, 57, 189, 187, 146, 254, 124, 124,
56, 56, 56, 104, 76, 68, 68, 19B
" REM shape*of*humanoids
2010 DATA 126, 36, 60, 24, 60, 102, 195, 255
‘ REM shape*o**platform
2020 DATA 63, ¥9, 193, 193, 127, 2B, 7, 3, 252, 19B,
131, 131, 254, 56, 224, 192
v REM shape *al iens
2030 DATA 255, 63, 15, 7, 3, 7, 255, O, 192, 240,
252, 255, 255, 255, 240, 3, O, O, 31, 249,
224, 255, 252, 240, O, O, O, 192, 248, 255,
0, O s REM space*ship*shape
2040 DATA 28, 28, 244, 199, 227, 47, 56, 56
3000 DATA 33, 1, 64, 37, O, 64, 26, 1, 31, O, 237,
176, 18, 35, 19, 62, 88, 188, 32, 242, 6,
22, 197, 26, 1, 31, 0, 237, 176, 18, 35,
19, 193, 16, 243, 201
5000 LET v = USR 32500
79
5010 LET x* = INKEY*
5020 LET nx = sx+(x* - < 1B> -
<x* - > B )t (sx > 0)
5030 IP nx = sx THEN GO TO 5060
5040 LET v* * SCREEN* (nx, sy+l> * LET w* =
SCREEN* tnx, sy+2> = LET x* =
SCREEN* (nx , sy+3> « LET v* = v *+w*+x*
5050 IF v* <> "***" THEN GO TO 0500
5060 IF SCREEN* (fix, sy+4) <> THEN BO TO 0500
5070 PRINT OVER H AT sx, sy-1 3 41 * ESfl F
GRA G ERA H fi e ft 1“ J AT nx, sy*
M fxt sn I GRfl F GRA G
GRfl H GRA I« EXT S_H f O
5080 LET sx = nx
5090 LET by = by-1 * IF by < O THEN LET by = 3!
5100 IF RND > .7 OR by = 31 THEN GO TO 5140
5110 LET nx = bx+(sx-l > bx)“(sx-l < bx)+(by = sy+2)
5120 PRINT OVER l; AT bx, by; 11 * SRO J M »
AT nx, by? ,J EXT SHI 2^ ERA J ”
5130 LET bx = nx
5140 IF bx = sx AND ABS (by-sy-l) <= 1 THEN
GO TO 8500
5200 IF x* <> "p" THEN GO TO 5290
5210 BEEP ,1, 4
5220 PLOT INK 33 OVER 13 B*sy+43, 170-8*sx
5230 DRAW INK 3; OVER 13 212-8*sy, Q
5240 BEEP .1,8
5250 PLOT INK 03 OVER 1! Btsy+43, 170-Btsx
5260 DRAW INK 03 OVER H 212-B*sy, O
5270 IF ax = sx AND ay > sy+4 AND ay < 30 THEN
FOR k ^ 1 TO 11 * BEEP ,1,5*
PRINT OVER !; AT ax, ay-1 3
*' * GHA D GRA E M * NEXT k *
LET ax = INT (15* RND ) * LET ay = 29 i
PRINT AT ax, ay- 13 “ EJa SRJ 4* SRft D
ERA E" LX I SHI O ? LET bc » sc+100
5280 IF bx - sx AND by > sy+4 AND by < 30 THEN
FOR k — X TO 5 - BEEP .1 t 10 ?
4 PRINT OVER l; AT bx, by 3 " EXT S.H.,1 2
* ERA J* 1 s NEXT k * LET bx =
1+ INT < RND * 14> * LET by = 30 s
PRINT AT bx, by3 " EXT 5J=U 2
* ERA J" EXT SHI O * LET sc = sc+20
5290 LET ay = ay-1 s IF ay < O THEN LET ay = 31
5300 IF RND > ,7 OR ay >= 29 THEN GO TO 5000
5310 LET nx = ax+(a* < iB)-t ? IF ax - 18 THEN
GO TO 5330
5320 LET v* ^ SCREEN* (nx, ay+1) ‘
LET rt* « SCREEN* (nx, ay+2> *
IF v*+w* <> THEN GO TO 7000
5330 LET ny = ay+(ax = 10 >
5340 IF ny <> ay AND SCREEN* (nx, ny+2> <> "* M
THEN GO TO 7000
5350 PRINT OVER 1| AT ax, ay; ”* SRfl D ILRD E M »
AT nx, ny; " EJil &iU 4* SRft D
&B& E" SiLL 5Uii O
SO
5360 LET ay - ny J LET ax = nx
6000 GO TO 5000
7000 IF ABS (bx-ax) 1 AND ABS (by-ay) I THEN
FOR k = 1 TO II : BEEP .1,5*
PRINT OVER l; AT ax, ayi "* GliB D
SRA E ,i * NEXT k =
LET ax = INT (15* RND > * LET ay = 29 i
PRINT AT ax, ay? " EXT aHI 4^ GHr) D
Rft E" EXT SHI O
7010 IF ABS (sx-ax) <= 2 AND ABS <by-sy) <= 2 THEN
SO TO 0500
7020 PRINT OVER l; AT ax, ay; " * fiflfi D Glia E“;
AT ax-1 f ay; " EXT SHI 4 4
GD GRA E" EXT S RI O
7030 LET ax = ax- 1 - LET ay - ay-1 - LET by ** by-1
7040 IF ay < 0 THEN LET ay - 31
7050 IF by < 0 THEN LET by - 31
7060 LET v = USR 32500
7070 PRINT OVER 15 AT sx, sy-1 ; " * GRfl F GBfl 6
GRfi H GRA I 1 '; AT *y *
w £ X T SRI 6^ GRA F GRA S
GRfl H GRfl 1“ EXT SHI O
7080 LET f = O
7090 FDR x * ax-3 TO as+3
7095 IF x >20 THEN GO TO 7125
7100 FOR y = ay+1 TO ay+3
7105 IF y < 0 OR y > 31 THEN GO TO 7120
7110 IF ATTR (x, y) = II THEN PRINT AT k, yi
INK 15 *'** 1 s LET f - T + l
7120 NEXT y
7125 NEXT x
7130 IF # - 2 THEN GO TO 7200
7140 PRINT AT ax, ay+3; INK 15 AT a* + i, ay+2
”***“; AT ax+2, ay+2 ?
7145 LET ay = ay+1 * PRINT OVER 13 AT ax, ay-1;
M * QRA D GHfl E f ' , AT ax, ay;
" StU 4* G BB D
GRfl E" EXT SHI 0
7150 LET e = e+1 i IF e = 3 THEN GO TO 8550
7160 GO TO 5000
7200 PRINT OVER 1 3 AT ax, ay; " * GHB D G££ E M 3
AT ax-1, ay; " SlHI 4
* GRfl D aRM E" Eft.T SHI O
7210 LET ax « ax-1 = REN LET ay = ay-1 =
IF ay < O THEN LET ay = 31
7220 LET by = by-1 * IF by < O THEN LET by 31
7230
LET v
* USR 32500
7240
PRINT
INK 4; AT ax + 1.
ayj
AT
ax+2, ay; ” * fififi B"
7250
FOR k
= ax-1 TO 0 STEP
-1
7260
PRINT
OVER 13 INK 4;
AT
k +1, ay? M GRfl
D GRA
AT
k+2, ay; *' ^ ORB
A";
AT
k+3, ay; “* GBB
B";
AT
kf ay; " GHB D
GRA E
AT
k+1, ay; ”*, GR£
A" 3
81
Freeway Frog
Copyright (c) Beam Software
You are a poor little frog desperately trying
to get homo across the highway. In your travels you
must brave trucks, motor cycles, cars and worst of
all high speed police cars that can appear at a moment's
notice* To control your frpg use the following keys
tr
to
move
up on the screen
A’
to
move
down
F f
to
move
right
cr
to
move
left
You get points for moving up and down, so to
get a higher score you can cross the highway as many
times as you like* When a frog reaches the top oE the
screen he is home and you then move onto the next one
to try and get him home.
How the program works
This program makes extensive use of the user
defined graphic set of your SPECTRUM. If you don't know
about these yet it might help to read chapter 14 of the
manual. The SPECTRUM only allows you to have 21 user
defined graphics at once. This program however requires
58 of them*
To allow the computer to access this many
characters requires that the UDG area be moved back
and forth between two or more sets of characters.
To do this we first need to make room for
the number of characters required* For a 16 K system
with only 21 user defined characters the UDG area is
located at memory locations 32600 to 32767. This is
168 bytes of memory or given 8 bytes for each character
this im 21 characters* Since we need 58 characters for
our gome we must have 464 bytes of memory for the UDG
area. This corresponds to locations 32304 to 32767 so
the first instruction in the program must be a
CLEAR 32303 {NOTE if a CLEAR is done after
any variables have been defined
in LET or DIM statements they
will be lost)
In this program we have three sets of specially
defined characters :
The first two have 21 characters each and the third only
16, So to access any set all we need do is point the
system variable UDG (locations 23675 and 23676) at the
correct block* These are
32600 for the first set (the normal set)
32432 for the second set (32600 - 168)
32304 for the third set (32432 - 128)
83
Mote the third set overlaps the second because
it only has 16 characters.
To set the correct value for UDG requires a
bit more calculation. The number to be POKEd into LfDG
Is obtained by:
POKE 2367 5, 'value*-256* INT( f value 1 /256)
and POKE 23676* INT( 1 value 1 /256)
Note we do not actually need to put these
lines into the program since we can calculate the
correct values ourselves and use them.
E.G
TO GET
POKE 23675
POKE 23676
32600
as
127
32432
176
126
32304
48
126
The values for the user defined graphics must
somehow be input to the computer and since we have
58 characters or 464 bytes, we need to input 464 values*
If these are put in data statements they take up a lot
of space (so much in fact that there is not enough room
for the game). And it would be silly to input them
every time the game was loaded. So to overcome this
problem the program has been split into two parts*
The first builds the user defined graphics and when
these are correct they are saved to tape as a block
of bytes. When the game is run this block of bytes is
loaded from the tape and the game can be played.
(Note you only need to load the block of bytes
when the game is run the first time after being loaded
from its tape* Once the characters are in the computer
they will stay there until the power is turned off or
another program overwrites them.)
Defining the Freeway Frog graphics
4
The following program will build the graphics
for this game. It is important to take a lot of care
when typing in the data statements! since any errors
will be very hard to find later, When the program is
run it will put all the data in the user defined
graphics area, then print on the screen all Lhe shapes
used,
You should see on the screen,
Four frogs in green at the top.
Each frog should look the same except
that they should all point in different
directions* (The first up, then right, down
and the last left)
Below these there should be
A white motor cylce, a red car, and a truck
all facing left.
And below these a white motor cycle
a yellow car and a truck all facing right
If all looks correct then the character set
nay be saved to tape. Use the command
SAVE "frogshapes" CODE 32304,464
(the name does not matter anything will do)
Don't forget to save the program as well in
case yoiii need it later.
The main program for Freeway Frog
The main program is fairly long so it might
be a good idea to type it in in stages being very
careful to check what is input cprefully.
In particular the sections of the program
that draw the shapes contain many graphic characters
and color control codes. Since these will look very
different once the program is run (e.g a graphic A will
not be an ’A T once the characters have been loaded)
it is very important to type these in carefully. It
is almost impossible to find errors later on*
When the program is run it will wait to
load the graphic shapes from tape. You should
put the tape with the bytes you saved from above
in the recorder and start it playing. If you wish
to run the game and the bytes have already been
loaded use RUN 26,
The following is a breakdown of the game
LINES DESCRIPTION
20 - 25
26 - 75
8.0 - 100
sets RAM TOP to allow room
for the user defined grpahics
and then proceeds to load them
from tape.
initializes all the variables used
sets the screen colors, the positions
of the cars trucks and motor cycles
and the variables used to change
the UDG character set,
(the program should be run from here
if the user defined characters have
already been loaded)
draws the highway
105 draws the frogs left on the screen
106 displays the score and high score
MO - 150
decides if a police car is to race
across the highway. If one is to
appear then the direction of its
travel is determined and it is
displayed,
500 - 530
checks to see if the frog has been
squashed all over the highway
If It has the program jumps Lo
line 4000
600 - 700
if the player is allowed to move
(he can move only once every 2
cycles of the main loop) the
keyboard is checked to see if
he wants to move. If,so the
position of the frog is altered
Its direction is changed if required
and the score is increased if he has
moved up or down* The old frog Is
then undrawn and the new one drawn.
7 50
moves all the motor cycles and redraws
them
800 - 820
every second cycle this moves all
the cars and redraws them
900 - 950
every fourth cycle this moves all
the trucks and redraws them
Then jumps back to 106 for another
cycle
990 - 999
removes a frog from the screen
The position of the frog is checked
to see if the highway needs to
be redrawn where the frog was
1000 hi 1070
This consists of four subroutines
used to draw the frogs facing In the
four different directions
1080 - 1117
These 6 subroutines draw the cars
trucks and motor cycles
2000 - 2001
draws all the cars on the screen
2010 - 2012
updates the positions of all the
cars (i,e the cars moving right
have there position increased and
those moving left decreased)
2100 - 2112
draws all the motor cycles and
updates their positions
2200 - 2201
draws all the trucks
2210 - 2212
4000 - 4010
4020 - 4070
5000 - 5020
updates the positions of all the
trucks
indicates to the player that a frog
has been run over* then decreases
the number of frogs left. If there
are any left the program jumps back
to start with the next frog
prints a game over message, updates
the high score if necessary and
asks the player if he wants to play
again.
A jump is made to here if a frog gets
home* the number of frogs left is
decreased and if any left the game
continues otherwise the program
goes to 4020
* * ¥ K
a
2210 - 2212
4000 - 4010
4020 - 4070
5000 - 5020
A
3COft 0
HIGH 3CORC 0
wm
A
■1 A
*****
87
USER DEFINED GRAPHICS FOR FREEWAY FROG
20 CLEAR 32303
25 LET z “ O ^ LET k = 255
30 FOR i = 32304 TO 32767
40 READ £ i POKE l, a s NEXT i
50 BORDER 0 * PAPER O = CLS
60
POKE
23675,
48 -
POKE 23676,
126
70
PRINT
AT 0,
9? "
EX T SHI 4
GHfl
A
GRfl
B
* *
GRfl E
Gflfl
F * * SMB I
GRfl
J
* *
GRP M
‘jfl A
n ex r am
0"
71
PRINT
AT 1,
9 5 11
&m am 4
QMB
C
S IBB
D
* *
&R A G
GRP
H ** SPP K
L
* *
&RB 0
EBB
p EXT SHI
0"
BO
POKE
23675,
176
81 PRINT i PRINT * PRINT
^ EXT SM I 5 i f PR D G R Pf D GRA D
D EpRft C EXT SHI 0 “
82 PRINT 1 E;Ll am 7 SBM ft £0A S
am o****** * 62 a mi 2
GRA N A O EXT SHI O*******
E X T am 3 y R A L GRfl I EXT SHI 5 ERA
sh i e fiafl i e gra 5iii a or a sh i a
ms e am o-
B3 PRINT " ** EXT SHI 7 £H£ T frElft U 5H,1 0
******* EXT SHI 2 GRA A PRA B
&fiB p iiEB o Em am o*******
p X T SHI 3 ORA M 6 P,A K EXT SHI 5 S R fl J
GRfl G GRfl G j jB A H GRA F EXT SMI O *'
¥0 POKE 23675, 8 B s POKE 23676, 127
¥l PRINT ; PRINT ^ PRINT *************
********** E-ii am 5 aaa c
^Rfl D GHft D Ei H fl D pR A D EXT ShLl 0 M
92 PRINT " ^ A EXT SHI 7 GBP R ia.fi.fl S
EXT SH I J. ^ * * * * EXT
atu 6 GRR N GR A O E 3 T SHI O*********
EX T SH l 5 frQA F G Ft A SH 1 8 gRH SHI 8 GHfl
4 SHI a g RA SHI 8 EXT ff H J 3 ftRA J GRA K
ta sp j O"
93 PRINT " EX1 aai 7 &RR T kfi£ U Em &tU O
******* ext SH I 6
gRft P GRfl 0 GRA A GRR B EXJI SHI Q
******* Em iHJ 5
GRA E ftRA G GRfl H GHft H ^Rfl I EXT
am 3 grr l gra h t am o'*
too IF INKEY* = "" THEN GO TO 100
HO BORDER 7 ? PAPER 7 * CLS
120 STOP
9000 DATA
9001 DATA
9002 DATA
9003 DATA
9004 DATA
9005 DATA
z <
1, 35, 37. UL 79,
223,
X
A
12B, 196, 164, 246,
242,
251
111
. 15, 31, 159x 220,
216,
120
246
, 240, 24B, 249. 59,
27,
30,
56,
113, 193, 252, 127.
31.
31,
192. 240 q 156, 192, 240. 24B, 244, 254
08
) r ^ ir • 1 . : " 1 *> ' J -
a 3 e *■ nr = i , 4 f* i k.' r n
a *. t Iflil.-ff ! I- -I -- i -
. ou act
a ►.-aii r
a «4C*ii i .
• ■ Cv • r « *. r, 4 r-
. a r 9 - 3 .
♦ ' <. ? •'€ li ’i
■ Cb * *£ *
1 l qt s: * t * El
!%•.•••
f • • • •
¥$ur >ov(
F»OM
TO
O <J I v * f ' * * »
' du t s -s.
a » i t tK«n t a * €
» bc-ttu c t f■• .•■*
Till v« Vf*t tO lO *
9006
9007
9000
DATA
DATA
DATA
31, 33, 31i 127, 252, 193, 113, 56
254. 244 * 240, 240, 192, 156, 240, 192
48, 120* 216* 220, 159, 31, 15, 111
12, 30, 27, 59, 249, 248- 240, 246
*, 223, 79, HI, 37, 35, 1, *
x, 251, 242, 246, 164, 196, 128, z
3, 15* 57, 3, 15, 31, 47, 127
9009
DATA
12,
30,
27.
9010
DATA
**
223,
79,
901 1
DATA
x.
251,
242
901 2
DATA
3,
15.
57, :
9013
DATA
28, 142,
131, 63. 254,
248, 240,
240
901 4
DATA
127. 47,
31, 15, 3, 57,
15, 3
9015
DATA
240, 240,
248, 254, 63,
131, 142,
28
9016
DATA
z, z, 3,
7. 15, 2, z, z
9017
DATA
7* x , x ,
159. Ill, 247,
240, 96
9010
data
2, z, z.
?, z, 254 p 254
. 254
9019
9020
9021
9022
9023
9024
9075
9026
9027
7028
9029
9030
9031
9037
9033
9054
9035
9036
9037
DATA
DATA
DATA
data
DATA
DATA
DATA
DATA
DATA
DATA
DATA
DATA
data
DATA
DATA
DATA
DATA
DATA
DATA
^ I *“ * ^ ^ — 7 —W ' P 1 ? * ” p
z. z, z« Z . Z i X, X ■ X
254, 254, 254 * 254, 254, 254, 254,
254, 254. 254, 4, 50 p 122, 122, 48
X, K, K. Z « Z , Z, Z . Z
x, x, x 3 z, 6, 15, 15, 6
2, 2t 250, 250, 254, 252, 252, 248
x, x* x ? x, 6, 15, 15, 6
254
A 2, 2, 2
z, z, z, z
12B, x, x,
240, 254,
1, 3, 1, 2
128. 192,
31, 63, II
254, 252,
274 ¥ x, x *
6,
15.
15,
6
54,
127
, 1B4
, 2:
17,
17
, 31,
31
62,
61
, 59.
3,
z.
63,
77.
193
2,
2 *
120 ,
192
X, X
, 254, z
* z
f 159,
11 1 t
246,
192 , 128
l, 16 v * 1iz, 1
234, 213, 206, 14
, 246, 239, 15, 6
32
255
9038
DATA
Zf
z, 192
!. 224.
240,
64, z , z
9039
DATA
z ,
Z f z f
Z , Z*
127,
127, 127
9040
DATA
A
Zf Zf
z , Z J
X. x *
X
t?04 1
DATA
127, 127,
L27,
32, 76, 94, 94
9042
DATA
127. 127,
127,
127,
127. 127,
9043
DATA
**
X . Vi *
z, 96 -
240,
240* 96
9044
D4TA
x,
A , Vim
z, Z *
z f z.
z
9045
DATA
X f
K m X ,
x i 96,
240,
240, 96
12
127, 127
9046
9047
9043
DATA
DATA
DATA
64 64.
2, 2, I
31* 63*
224, 144,
27, 63, 63, 31
9049
DATA
248,
240,
248*
124, 188,
220, 192, 128
905U
DATA
z , z
. z,
z, z ,
z, 1, 3
9ii51
E*A1A
2 j z
- z *
z . z *
252, 134,
131
9m52
DATA
J 5 ,
127*
x, 247* 246* 111
, 15 * 6
9053
DATA
1 T X
, X *
X , x,
127, z, z
9054
DATA
1 * 3
1 3,
7, 7,
14, 238. x
9055
DATA
12B.
192,
128,
z, 192, 32
, 112, 248
9r-56
DATA
177*
63,
63, S7- 171, 115
, 112, 32
9057
DATA
240*
252,
206,
138 t 149,
14, 14* 4
89
FREEWAY FROG
20 CLEAR 32303 * RANDOMIZE
25 LOAD 11 - CODE
26 LET hi = O
30 LET ml = 2* INT RND *15 £
LET m2 = 2* INT RND *15
33 LET tl = INT RND *30 * LET t2 = INT RND *30
34 LET cl = 2* INT RND *30 £
LET c2 = 2* INT RND *30
35 LET ce = 2 £ LET cf = 6
36 LET pz = 4 £ LET tz = 4 £ LET mz * 2
40 BORDER O £ PAPER O £ INK 7 i CLS
45 LET f = 4 £ LET fc = 5
50 LET uL = 23675 * LET uh * 23676
55 LET £!= = O
60 LET LI = BB : LET L2 = 176 £ LET L3 = 4B
70 LET hi = 127 £ LET h2 « 126
75 LET LID - 0 £ LET Lll = 9 s LET L12 - 7 £
LET L2G = 13 £ LET L21 = 14 £ LET L22 = 12
BO PLOT 0, 3B £ DRAW 255, O £ DRAW O, 1 £
DRAW “255 s O
90 PLOT O, 120 £ DRAW 255, 0 * DRAW O, I £
DRAW -255, 0
100 FOR u = 2 TO 256 STEP 0 £ PLOT x, 03 £
DRAW 4, O £ DRAW Q, 1 £ DRAW -4, O £ NEXT x
105 LET pa - 20 * LET py =* 20 £
FOR k = O TO <fc-1)*3 STEP 3 £ LET px = x £
GO SUB 1020 £ NEXT x
106 PRINT AT O, Q; " mi 6Score* SHJ 7" 3 sc 5
AT 0 3 14; " EXT fiJdi 6HIGH*SC0RE* EXT SHI 7"! hi
110 IF RND < ,9 THEN GO TO 500
115 IF RND > -5 THEN GO TO 150
120 LET c = 5 £ FOR j = 1 TO 6 £ BEEP .2, lO £
BEEP .2, 20 ? NEXT J £ FOR x *= -4 TO 30 STEP 2
£ GO SUB 1080 £ NEXT X
130 GO TO 500
150 LET c = 5 £ FOR j = 1 TO 6 £ BEEP -2, 20 £
# BEEP .2, 1.0 £ NEXT j £ FOR x = 30 TO -4
STEP -2 £ GO SUB 1H0 : NEXT x
500 IF py > 15 OR <py < 12 AND py > 9) OR py < 6
THEN GO TO 600
510 LET i = 22526+py*32+px
520 IF PEEK l 04 OR PEEK <1+1> <> 4 THEN
GO TO 4000
530 [F PEEK < j +32) <> 4 OR PEEK <i+33) 0 4 THEN
GO TO 4000
600 IF pz THEN LET pz = pz-1 £ GO TO 700
610 LET pz — 1 - LET z* » INKEY* £ IF z* = "" THEN
GO TO 700
615 GO SUB 990
620 LET py ** py-<z* = = "a")
630 LET px * px + Cz* = M p M )-(zt = <T o**>
640 IF z* = "q M THEN LET pa = O
641 IF z* = “p" THEN LET pa =* 20
90
642 IF 2* = "a" THEN LET pa = 40
643 IF z* = M o" THEN LET pa = 60
650 IF py - O THEN GO SUB 5000
660 LET sc = sc+10*<z* = "q" OR z* = '*a“>
700 GO SUB lOOO+pa
750 GO SUB 2100
BOO IF roz THEN LET mz = mz-1
BIO GO SUB 2000
020 IF NOT mz THEN LET mz = 2 * GO SUB 2010
900 IF tz THEN LET tz = tz~!
901 GO SUB 2200
902 IF NOT t 2 THEN GO SUB 2210 £ LET tz = 4
950 60 TO 106
990 PRINT AT py, px 3 ' V * " » AT py-*-!, px ; "** pl *
991 IF py * in OR py = 11 THEN PLOT px*0+2, S3 £
DRAW 4, 0 s DRAW O, 1 £ DRAW -4. O *
PLOT px*B+10, 83 £ DRAW 4. O s DRAW O, 1 £
DRAW -4, O £ RETURN
995 IF py = 17 OR py = 16 THEN PLOT px*B, 30 £
GO TD 990
996 IF py <> 5 AND py <> 4 THEN RETURN
997 PLOT px*0, I28
990 DRAW 16, O = DRAW O, 1 £ DRAW -16, 0
999 RETURN
lOOO POKE uL. L3 £ POKE uh, h2
1010 PRINT INK T; AT py, px ; - EH B A EHB B M i
AT py+1, px; ” GRA C ERA D* 1 s RETURN
1020 POKE uL, L3 £ POKE uh, h2
1030 PRINT INK T ; AT py, px 3 " EH£ E ERA F" 3
AT py+1, px i " ERA G GRft H" £ RETURN
1040 POKE uL, L3 £ POKE uh, h2
1050 PRINT INK f; AT py, px| " QBB I SRR J " 3
AT py+1, px; " GRfl K GRfl L M * RETURN
1060 POKE uL, L3 £ POKE uh, h2
1070 PRINT INK f, AT py, px ; * EHB M EBB N”3
AT py+1* px; 11 ERA o ERA P M i RETURN
IO0O POKE uL, LI £ POKE uh, hi
1095 IF x < 0 THEN PRINT AT LiO, 05 INK c;
N ERA O * C1 —x TO J 3 AT LI 1, 0 3
* " GRP P GRft Q GRft P GRA Q t jpfl A ERA B"
<l-x TO > £ RETURN
1090 IF x > 26 THEN PRINT AT LIO, x; " EAJ EHI
INK c 3 ■* ERA N GRA O" i TO 3C-K)5 AT Lit, x
” E .XT SHI 0**"3 INK C 3 " EEB P ERA Q"
t TO 30-x > s RETURN
1095 PRINT AT LIO, x; “ EXT SHI O^"; INK c;
M ERA N E£LA AT Lll , x3 " EXT SJdi 0
3 INK c; " ERA P ERA Q ERA A ERA B H £
RETURN
tlOO POKE mL, LI £ POKE uh, hi
1104 IF x >= O AND * < 25 THEN PRINT AT L12 f *5
*■ t-'XT SM I EXT SHI 5 GR A C ERA D GRA
ERA D ERA D" 5 AT LIO, *3 11 EXT O
A EXT SHI 5 GRA F ERA SHl 0 gRfl SHI 0
RHfl SH i 8 ERA sh i B 6a_T 1 3 gha J
K pi ; AT Lit, x; " EXT £HJ O* EXT SH 1
9J
ERA E gPj ft G ERA H ERA H ERA I EXT SH I 3
5RA L ERA IT' ~ RETURN
1I0S IF x < -5 THEN PRINT “ EXT am 3"; AT LIO, G3
" U&B J SitLB K"(-5 -k TO >3 AT L1 1, Oi
" ER A L ERA M"<-5-x TO > * RETURN
1112 IF X < 0 THEN PRINT AT L12 ff 03 11 EXT SHI 5" 3
“ ERA c fiBft D BBfl D ERA 0 ERA 0 “ {-* TO ) %
AT L10, 0; M ERA F GRfl SHI 8 ERA SHJL 8
ERA SHI S ERA SHI 8 " (- x TO 1 3 " E X T SHI 3
ERA J ERA AT LU, 0; M EXT j 5” ;
" ERA E ERA 8 ERA H GRA H ERA 1 11 C~x TO >3
M EXT SHI 3 ERA L ERA M" s RETURN
1115 IF x =25 THEN PRINT AT L12, m3
" EXT SHI 0* EXT SHI 5 ERA C ERA 0 ERA D
JaELQ D D'* i AT LIO, x5 " EJH atLi 0
* P>- T ^H I 5 f?Rft F ERA SH I Q ERA SHI 8
ERA SHI Q ERA SHI S EXT I 3 GRA J " ;
AT Lll f x; “ EXT am EXT SHI 5
GRA E GRA G ERA H ERA H fiBfl I X £HI 3
£H£ L n i RETURN
1117 PRINT AT LI2, x; 11 EXT SH I O* EXT SHI 5 M S
" SR A C ERA 0 GRA 0 GRA 0 GRA 0* 1
i TO 31-x) ; AT LIO, X? " 6JiI 0
* E X T SHI 5 11 ; M GRA F GRA SH I 8
GRA SHI 8 GRA SH I Q GRA SH T 8"
( TO 31-x>; AT Lll, x; " EXT SHI O
A EXT SH I 5" ; “ l^R A E GRA G GRA H
ERA H ERA l»{ TO 31-X ) -
RETURN
1120 POKE uL, LI s POKE uh, hi
1125 IF X < 0 THEN PRINT AT LIO, 03 INK 7;
" UHB R S" I AT Lll, 0; INK 73
" GRA T ERA U" i RETURN
1130 IF x > 28 THEN PRINT AT LIO, xi “ EXT am 0^“
3 AT LI 1 » x3 ■ EXT SHI O**" * RETURN
1135 PRINT AT LIO, *3 " EXT am EXT SHI 7
ERA R QRA S £^T SJtU 0"| AT Lll, x;
“ E X T 5 HI 0 * * EXT SHI 7 GRA J GRA U
Ej ^T SHI G“* t RETURN
1140 VOKE uL, L2 * POKE uh, h2
1145 IF x >26 THEN PRINT AT L20, x3
INK C! H ^ E.RA N ERA 0" ( TO 32~x ) 3
AT L21 * x| INK cl " ERA A EH A B ERA P
GRA Q"< TD 32—x > * RETURN
1150 IF x < O THEN PRINT AT L20, Oi INK ci
" * GRA N ERA O EXT SHI 0** M
(“X TO > 3 AT L21, 0 3 INK C3 " ERA B ERA F
ERA Q Sill TO > ‘ RETURN
1155 PRINT AT L20, «3 INK C3 ERA N ERA O
Ej<T am 0** M i AT L21, x; INK ci
H ERA A ERA B ERA R GRA Q EXT SH I O* *" ±
RETURN
1160 POKE uL, L2 - POKE uh. h2
1163 IF x >= O AND x < 25 THEN PRINT AT L22 ( x;
M EXT SH1 0 Ai EXT SHI 5 ERA D ERA 0
SJ&B D ERA 0 QRB C EX_L Sili 3 AT L20, *3
92
" EXT SH i 3 G H R L GRR I EX T SM 1 5
GRP. SH I 0 GRR SH I 0 GRR SH I 0
qrb am a aaa e am o*-i at lzi, x;
" EXT SHI 3 GRR M GRR K EX T SH1 5 GRR J
GRR G GRR G GRR H gRft F 5 ft T &JdJ O*'* ±
RETURN
U65 IF x = -l THEN PRINT AT L22 f O; " EJLE SJdi O
* EXT SHI 5 GRR D GRR D GRR 0 GRR 0
GRR C GXT &tU 0* M ; AT L20, O;
" F XT SH I 3 GRR I EXT SHI 5 GRR SH I 0
GRR SHI 8 GRR SHI S GRR SH 1 B GRR E
am O** 1 ; AT L2l« 0i
■■ EXT SH I 3 GRR K EXT SHI 5 GRR J
GRR G GRR B GRR H GRR F EXT SHI O ^ " S
RETURN
1170 IF >i < -1 THEN PRINT AT L22 s 0? M EXT SH I 5";
11 * GRA o GRR D GRR D GRR D GRR C
EXT 5H1 TO > 5 AT L20, Oi
" EXT SHI 5" ; ■' ^ GRR ^ H I fl GRA SHI 0
GRR SH r 0 GRR SH I 0 Kflfl E F X T SH I O**'
C-x TO >; AT L21 , Of " EXT £l±i 5";
" _ GRR J GAR B GRR G GRfl J-J ERA F
SftT mi O/'i-K TO ] ± RETURN
1173 IF X >29 THEN PRINT AT L20 t x! 11 EXT fiHJ 3" i
" kaa L UELD I’M TO 32~x>? AT L2t s xi
M GRFj M ERA K" ( TO 32-x> = RETURN
1175 PRINT AT L22, X5 m EXT SHI Q * * EXT am 5” i
fP GRR D £££ 0 D GRR D GRR C"( TO 30-x);
AT L20, x; " EXJ aBi 3 GRR L tjRA I
5ft J 1 5" ; " GRA ^ H I g ftRA SHI 0
GRR SHI 8 GRR SHI 0 GRR E» ( TO 30~X > ;
at U 2 i < x; ■* ajix am 3 slbjq m aaa k
EXT SHI 5"; GRR J GRR G GRR G GRR H GRR F”
< TD 30~x> = RETURN
1180 POKE uL T L2 * POKE uh, h2
1105 IF x >29 THEN PRINT AT L2C f x; INK 7;
” GHR R GRR S"; AT L21 , *5
" QBB T EBfi U" ; RETURN
1190 IF x < O THEN PRINT AT L20, O; INK 7;
“ GRR 5 EXT am TO ); AT L2i, 05
INK 7; " EBB U EXJL £K1 D**“
(-x TO > i RETURN
1195 PRINT AT L2G, x; 11 5ft T £HI 7 t gRPi R GRR S
EXT am 0^"i AT L21, xl
M FXT SHI 7 fiP_A T gpo U E x T SH l 0**" S
RETURN
2000
LET
c =
ce : LET
X
= cl s
GO SUB 1000
2001
LET
c =
c-F * LET
x
=* c2 ;
GO TO
1 140
2010
LET
cl
= cl+2 s
IF
cl = 32
THEN
LET
cl =
-4
2011
LET
c2
* c2-2 -
IF
c2 - -h
THEN
LET
c2 =
30
2012
RETURN
2100
LET
X —
ml - GO
SUB 1120
2101
LET
ml
= ml+2 i
IF
ml = 32
THEN
LET
ml -
-2
2110
LET
X -
m2 - GO
SUB USD
21 i 1
LET
m2
- m2-2 s
IF
m2 * —4
THEN
LET
m2 *
30
21!2 RETURN
93
2200 LET x *= tl i GO SUB IlOO
2201 LET x = t2 s GO TO 1160
2210 LET tl = tl+I t IF tl = 32 THEN LET t1 = -7
2211 LET t2 = t2—1 ± IF L2 = -8 THEN LET t2 = 31
2212 RETURN
4000 LET f = 2 J FOR i = 50 TO 1 STEP -5 * GO SUB 990
t GO SUB lOOO+pa * BEEP .02, i * NEXT i
4005 GO SUB 990 * LET 4^4
4010 LET fc = fc-1 s IF 4c <> O THEN GO TO 105
4020 PRINT AT 1, 10* "Garnerver"
4030 IF sc > hi THEN LET hi = sc J PRINT AT 2, 3;
"But ^your *score Js *the *new
************ IGH* SCORE "
4040 PRINT AT 4, 65 "HiT**y■ *to*p1 ay*again"
4050 IF INKEY* - M " THEN GO TO 4050
4060 IF INKEY* - "y 1 ' THEN GO TO 30
4070 STOP
5000 FDR i = 1 TO 50 STEP 5 s SO SUB 990 *
GO SUB lOOO+pa * BEEP .02, l * NEXT i
5005 GO SUB 990
5010 LET fc *= fc-1 * IF fc <> O THEN GO TO 105
5020 GO TO 4020
0
94
High Resolution Graphics
Copyright (c) Beam Software
description
This program can be fun to just play around with, and
see greatly magnified the USER DEFINE GRAPHIC CHARACTER
SET.
But it is a MUST to COMPUTER programmers who want to
change the GRAPHIC CHARACTERS into HIGH RESOLUTION
graphics for their own use. eg GAMES.
An exceedingly powerful editor is implemented with
features like:
Dynamic display of graphic development
Instant blanking of characters
Instant filling of characters
Large editing simulation display
Mirror image of existing characters
Four directional wrap around cursor
Option of one, two or four characters
Easily identifiable colours
Instant abort at any time without changes
More than these, at the end of editing, the memory
location of these characters are automatically updated
and all data corresponding to the characters are
displayed with the option of sending them to the printer.
You will be amazed at how handy this program can be.
When the computer is doing its processing, you will be
informed throughout,
To use the program :
EDITING
cursor control
# 5 cursor left
6 cursor down
7 cursor up
8 cursor right
1 turn pixel under
0 turn pixel under
operation control
b Blank all pixels
f Fill all pixels
m Mirror image of the character blocks
s Save changed character blocks in memory
E Escape from editing with no changes to
character blocks (Note - you must use (shiit) e)
cursor ON.
cursor OFF
95
PROGRAM STRUCTURE
The program uses an array Co simulate the memory
bytes which defines the character block*
The character set of first USER DEFINED GRAPHIC
character starts at memory location 65368 for 48K machine
and 32600 for 16 k machine* Then follows 8 bytes of shape
definition for that character*
The structure of the program is as follows;
INPUT;
SET VARIABLES OF DISPLAY FILE
INPUT STARTING OF CHARACTER BLOCK
INFUT NUMBER OF CHARACTERS (1 or 2 or A)
DEFINE DIMENSION OF simulation! memory address ptr*
mirror Image working ARRAYS
MAIN LOOP:
INITIALISE simulation,, memory address ptr ARRAY
READ MEMORY BYTES INTO simulation ARRAY
DISPLAY ENLARGED and REGULAR SHAPE OF CHARACTER BLOCK
PERFORM EDITING ROUTINE
UNTIL SAVE OS EXIT
PROMPT PRINTER OPTION
IF MORE CHARACTER TO BE REDEFINE GO TO INPUT:
EDITING routine
DETERMINE SIZE OF ENLARGED BLOCK TO BE EDITED
El: FLASH CURSOR
ACCEPT CONTROL KEY INFUT
UNFLASH CURSOR
CASE ; '5 1 or 'B' calculates new cursor position
goto El:
"0* set current simulation array
element to 0! update screen
display
goto El;
4 1 1 1 set current simulation array
element to 1, update screen
display
goto El;
■f 1 or 'b 1 fill whole simulation array to 1
if 1 f 1 t to 0 if *b*
redisplay character block
goto El:
1 s r prompt saving option
if save then store simulation
array into memory
if not save then goto El:
f m T swap simulation array rows back to
f ront
goto El:
'E f return
96
SPECIAL NOTES
The flashing and unflashing of the cursor is done by
changing the attributes of character position in the
display File, The memory location of the top left
character position in display file is 22528, therefore
3040 LET a = 22523 * 32 * x + y : POKE a, PEEK a + 128
will set line x column y to flash; in the same manner
3060 POKE a, PEEK a - 128
will set that position to unflash.
To facilitate the COPY of screen onto the line
printer, a blank pixel is displayed as PAPER yellow INK
BLACK; a filled pixel is displayed as PAPER white INK
BLUE.
Print instruction is used to display ENLARGED
character size and Plot instruction to display REGULAR
character size.
In order to reference the right USER DEFINED GRAPHIC
character, any lower case character INPUT will be
adjusted to UPPER case by
8060 LET K$ = CHK$ ( CODE K5 - 32 )
A testing is also performed to check if the INPUT
character is beyond the USER DEFINED CHARACTER set by
8070 ... OR ( CODE K$ + nc + 79 - 1 ) ) 164
ie the ASCII code of the first character in upper case
plus the number of characters to be defined plus 79 minus
1 should not exceed 164, which is the ASCII value of the
last USER DEFINED GRAPHIC character.
To obtain the start of the 8 memory bytes that define
a particular USER DEFINED CHARACTER and put it into the
array, refer to
8150 LET 5(1+1) = USR CHR$ ( CODE K$ + 1 )
§
The logic behind the setting of mirror image of the
array is by dividing the array into two array and
interchanging the two f-ar-end elements and moving inward
until the middle of the array is reached. In other
words, an eight elements row will be divided into two
halves of 4 elements each. The first element of the first
half is swapped with last element of the second half.
Then the second element of the first half will be swapped
with the second last element of the second half. This
will continue until the last element of the first half is
swapped with the first element of the second half. You
can refer this logic to lines 3330 — .3400,
97
HIGH RESOLUTION GRAPHICS
100 REM USR
110 REM User^define^GRAPHIC
120 GO TO SOOO
lOOO REM Draw^character*5et
1010 REM Input*r, c| Btarting^coordinates
1020 PRINT AT G, 11|
s PRINT AT 9, 115 "**"
s FOR H = 1 TO nc
1030 LET hr = 0t(H - 3 DR H = 4)
i LET he - 8* CH = 2 OR H = 4)
1040 FOR I ^ 1 TO 8
1050 FOR J - 1 TO B
1060 PRINT AT (I+r+hr), tJ+c+hc>i
1070 IF BCI+hr, J+hc) = O
THEN PRINT PAPER 65 INK O; *"*"
i GO TO 1090
1080 PRINT PAPER 7; INK. l; - SH-fi SHI B 1 '
s PLOT 87+J+hc f 112-1-hr
1090 NEXT J
1100 NEXT I
lllO NEXT H
1120 LET L* = 4 m^ Jik * Jt *********^*
1130 RETURN
2000 REM
2010 REM ch*r A into A array
2020 REM Input^K*, Output *B< I f J)
2030 REM
2040 FOR H = 1 TO nc
2050 LET hr = 0* (H > 2>
± LET he -8?<H = 2 OR H - 4)
2060 FOR I = 1 TO 8
2070 LET m = PEEK <s(H)+I-l)
2080 FOR J = 8 TO 1 STEP -1
2090 LET B < I+hr f J+hc) = m~2* INT (m/2)
2100 LET m * INT lm/2>
2110* NEXT J
2120 NEXT I
2130 NEXT H
2140 RETURN
3000 REM Edit^CHAR, x = row, y *= col
3010 REM Input*B<I f J)
3020 LET hr = 8*<ne > 2>
s LET he = 8*tnc - 2 OR nc = 4 )
3030 LET x - r+1 * LET y = c+1
3040 LET a = 22520+32* x+y
s POKE a, PEEK a+12S s PAUSE 200
3050 IF INKEY* = 11 " THEN GO TO 3050
3060 LET m = INKEY* * POKE a, PEEK a-12B
* REM unflash*old A pos
3070 IF M* < "5" OR M* > "8" THEN GO TO 3150
3090 LET y = y+(M* = "B"
AND (x <> B+hr DR y <> 22+hc)>-<M* = "5 11
AND (x <> 1 OR y <> c+l>)
9B
3090 LET x = x+<MS = "6")-<MS * *'7 n }
3100 IF x > 9+hr THEN LET x * 1
3110 IF x < 1 THEN LET x = 8+hr
3120 IF y > 22+hc THEN LET y = c+1 ; LET x = x + 1
3130 IF y < 15 THEN LET y = 22+hc i LET x - x-1
3140 GO TO 3040
3150 IF n$ <> "O" AND MS <> "i" THEN GO TO 3190
3160 PRINT AT x, yl
3170 IF B<x~r, y-c) ^ 1 AND MS = "0 M
THEN LET BCx-r, y-c) = O
s PRINT PAPER 6; INK O; '■**
5 PLOT OVER 1? 87+y-c, 112-x+r
~ 60 TO 3040
3180 IF B t x —r f y-c ) = O AND MS = *' 1 11
THEN LET B<x-r, y-e> = 1
s PRINT PAPER 7; INK 1? " mS B"
* PLOT 87+y-c, 112-x+r * GO TO 3040
3190 IF EXT 5J±i OM* <> "f* AND MS < > "F" AND MS < > "b"
AND MS <> M B" THEN GD TO 3240
3200 LET b = 4H* = **f» OR MS ^ "F")
3210 GO SUB 4000 ± REM init*ARRAY
3220 GO SUB lOOO - REM drax^char
3230 GO TD 3030 * REM start ^again
3240 IF h* <> N E“ THEN 60 TO 3260
3250 PRINT AT 19, Oi INK 25 "No^change^to^thi s
^character!" s RETURN
3260 IF MS <> “5“ AND MS <> M S" THEN GO TO 3320
i REM edit*inkey
3270 PRINT AT IB, O; "Store^th i s?^Cy,cr A n>*";
32B0 LET a* = INKEYS i IF el <> "y- AND et <> "n"
THEN GO TO 32B0
3290 PRINT INK 2; e* * PAUSE 50
3300 IF eS = “y" THEN BO SUB 5000 * RETURN
3310 FOR M = 1 TO 3 * PRINT AT 17+M, O;
s PRINT H *****************
II m
S NEXT M i GO TO 3030
3320 IF Ht <> *'m H AND MS <> "M" THEN GO TO 3040
3330 PRINT AT O, 26; FLASH 1; INVERSE 13 INK 3
S “MIRROR" 4 LET fc = INT <be/2+.5>
3340 FOR I = I TO br
-3350 FOR J = 1 TO Tc
3360 LET M = B11, J>
3370 LET B fI, J> ^ B(I, bc-J+l)
3380 LET B<I, bc-J+1) = M
3390 NEXT J
3400 NEXT I
3410 PRINT AT O, 263 '■******"
3420 GO SUB 1000
3430 GO TO 3040
4000 REM Initialisa*simulation*ARRAY
4010 FOR I = 1 TO br
4020 FOR J = 1 TO be
4030 LET B(I, J> - b
4040 NEXT J
4050 NEXT I
99
4060 RETURN
4070 REH
5000 REM Transpose*array*to A ntem
5010 PRINT AT EL&I £J±l OO, 255 FLASH I ? PAPER 3i
5 "SAVING"
5020 FOR H — 1 TO nc
5030 LET hr = 8*<H > 2)
* LET he ^ B*(H = 2 DR H M)
5040 FOR I = 1 TO 8
5050 LET t = O
5060 FOR J - 8 TO 1 STEP -1
5070 IF B (I +hr, J+hc> =* 1 THEN LET t = t+2^tB-J>
5000 NEXT J
5090 POKE Is(H>+I-l>» t
5100 NEXT I
5110 NEXT H
5120 PRINT AT O, 25| "******"
5130 PRINT AT O, 25; PAPER 3; INK 7; “SAVED* tw
5140 RETURN
6000 REM
6010 REM 1 i st ^memory A val ue ^of *char
6020 PRINT AT 0, Oi M „„****"
6030 FOR H — 1 TD nc
6040 LET he - <H = 2 OR H - 4)*5+1
t LET hr ^ <H > 2)*9
6050 PRINT AT hr, hc-1 | PAPER 1| INK 7|
; CHR* ( CODE K*+H-1>S
6060 FOR I = 1 TO B
6070 PRINT AT hr+I, he; PEEK (SfH>+I-l)
6000 NEXT I
6090 NEXT H
6100 LET UB = CODE K*+79
* PRINT AT 8, 115 OVER 05 CHR* UG3
6110 IF nc >= 2 THEN PRINT CHR* (UG+1)
6120 IF r>c = 4 THEN PRINT EXT £i±J O AT 9, 11
; OVER O; CHR* CUG+2)| CHR* <UG+3>
6130 RETURN
8000 BORDER 5 * INK O s PAPER 7 - OVER 0 - FLASH
# s CLS
8010 REM key^repre^of *ehar * DIM K*U)
8020 PRINT "Which^CHARACTER^to^be^rede*ined?"
i PRINT ,1 (fiito A U) 11
8030 LET K* ** INKEY* * IF K* >= “A* AND K* <= “LT
THEN GO TO B060
8040 IF K» < "a" OR K» > f, u" THEN GO TO B030
0050 LET K* = CHR* ( CODE K*-32>
0060 PRINT K* * PRINT * PRINT
"How^many ^characters?* < I ^—*.4) *" 5
8070 LET nc — < C CODE INKEY* )-48)
i IF nc < I OR nc > 4
OR i CODE K*+nc+79-l> > 164
THEN 80 TO 8070
8000 IF nc = 3 THEN LET nc ^ 4
8090 PRINT nc ± FDR I - 1 TO 50 a NEXT I s CLS
8100 DIM S(nc)
s REM meifior y * 1 oc at i on A o i * char ac t^r
INK 7
100
Bi 10 LET br = StCl+Cnc = 4) >
5 LET be - 8*<l+<nc > 1H
8120 DIM CCbc) * DIM BCbr, be)
* REM si mulati on ^array
8130 FOR I = 0 TD nc-1
8140 PRINT INK 25 CHR* ( CODE K*+ I) ;
? REM printiChars
0150 LET S(I+1> = USR CHR* C CODE K*+I >
* REM mem*loc A of+char*set
0160 NEXT 1
8170 PRINT AT O, 25i FLASH 1; PAPER 1 EXT S±Ll 03 INK 71
"LOADING"
8100 LET to = O s BO SUF 4000
s REM initial i se *ARRAY
8190 GO SUB 2000 * REM char*to*array
8200 LET r ^ O * LET c - 14
8210 GO SUB 1000 s REM Restore^CHAR
8220 PRINT AT O, 253 "** *****“
8230 GO SUF 3000 $ REM Edit *CHAR
8240 GO SUB 6000 * REM I i st ^meroor y *val ue
0250 PRINT AT 20, 05
"Copy 4 onto 4 printer?* <y*or 4 nl"3
8260 LET g* = INKEY*
* IF g* <> M y" AND g* <> N n" THEN GO TO 8260
8270 PRINT g*
8280 IF g* = "n" THEN GO TO 8320
8290 PRINT AT 2l f 03
“Press*any *key *when A read y - 11 ? PAUSE 2000
0300 IF INKEY* = “" THEN GO TO 8300
8310 COPY
8320 PRINT AT 20, Oi L* s PRINT AT 21, Oi L*
8330 PRINT AT 21, Oi L*
0340 PRINT AT 20, OS
H Change*any*ather i chars^*<y*or"3
* PAUSE 200
8350 LET g* - INKEY* ± IF g* <> M y" AND g* <> "n*
THEN GO TO 8350
8360 PRINT g*
8370 If g* = M n" THEN STOP
8380 CLS i RUN
101
Line Renumbering
Copyright (c) Beam Software
DESCRIPTION
These are a few programs that you may find useful if
you are in the habit of developing programs and find
youself at the end of the development with oddly numbered
lines and no room to fit in that last brilliantly
concieved routine in the middle.
Model 1 (RENUM1) is a short renumbering model
assuming automatic renumbering from line 100, the first
line, Including all lines before 9990, where the model
I renumber1ng program starts. Line increment for model 1
is 10.
Model 2 (RENUM2) is a short renumbering model similar
in features to Model 1 except it displays on the screen
all GOTO and G0SUB within each line together with the new
line number .
GOTOs and COSUBs are not renumbered because the ZX
SPECTRUM supports computed GOTO and GOSUB and these are
too difficult for the program to renumber . The best we
can do is to report where they are in the new renumbered
version and let you to work out what changes need to be
made *
Model 3 (RENUM3) is the long version of the
renumbering program . It allows you to renumber a block
of lines in any line increment value with GOTOs and
GQSUBs displayed . It also allows you to PRINT those
GOTOs and GOSUBs report onto the line printer. Not only
that* it is a complete screen driven program with high
emphasis on USER FRIENDLINESS.
To use any of these Models* you need to MERGE the
program instead of LOAD them because the later method
will result in a COMPLETE wipe out of your program from
the primary memory.
The following is the format of a BASIC program line:
2-byte:
front
2-bytei
front
n-byte:
The
line number with a more siginifleant hyte in
line length with a less significant byte in
line content Includes last end of line character
starting address of the BASIC program is 23755.
102
MODEL 1 RENUMBERING
Use RUN 9990 or GOTO 99 90 to start the program*
PROGRAM STRUCTURE
INITIALISE NEW LINE # TO 100
INITIALISE MEMORY POINTER TO 23755
LI: IF'ENCODED LINE # )= 9990
stop
DECODE NEW LINE # INTO MEMORY
GET INCREMENTED NEW LINE #
MOVE MEMORY POINTER TO NEXT LINE
GO TO LI:
SPECIAL NOTES
To delete the renumbering program after use, you may
need to load the LINE BLOCK DELETE program, another
exciting UTILITY program of this book.
The program is from 9990 to 9995.
MODEL 2 RENUMBERING
Use RUN 9988 or GOTO 9938 to start the program ,
PROGRAM STRUCTURE
INITIALISE NEW LINE INCREMENT, BEGINNING OF BLOCK*
END OF BLOCK
FIND MEMORY LOCATION OF THE BEGINNING OF BLOCK
LI: IF tm OF BLOCK LINE REACHED THEN STOP
POKE NEW LINE INTO MEMORY
REPORT ANY GQTOs AND GQSUBs within the line
UPDATE MEMORY LOCATION POINTER & LINE §
GOTO LI:
SPECIAL NOTES
Since this MODEL has a built in code for finding the
memory location of the start of block, you can then
change the variables in line 9988 to suit your operation.
Again, if you want to delete this short program, you
can either do it manuallly or you can use out LINE BLOCK
DELETE program in this book.
No printer facilities are provided to copy the
103
displayed GOTOs and GOSUBs report; ie You have to do it
manua1 I y,
The program is from 9968 to 9999.
MODEL 3 RENUMBERING
Use RUN 9900 or GOTO 9900 to start the program.
PROGRAM STRUCTURE
Screen handling technique Is used to input the
starting and ending line number block to be renumber * the
increment of lines and the new starting line number of
the block.
All the four input values will be round up to an
integer .
The structure of the program is as follows;
INPUT STARTING and ENDING LINE NUMBER of the block
INCREMENT and NEW STARTING NUMBER of the block
FIND start of memory of starting line
CALL RENUMBERING MODULE (same as model 2)
OPTION AS TO CONTINUE RENUMBERING OTHER BLOCK
OR TO COPY REPORT OF GOTOs and GOSUBs
OR TO EXIT WITH OPTION OF DELETE MODEL 3
SPECIAL NOTES
This model gives you the option of deleting the model
itself at the end of the operation .
The renumbering of the block lines is inclusive.
The program is from 9900 to 9999*
you choose the option of deleting the renumbering
model itself* At the end of the deletion, you need to
type 9900 (ENTER) to finalise the deletion. This is
because all of the renumbering program have been turned
into one very long REM statement.
If you do not choose the delete option and at the end
you do want to delete the whole renumbering program, you
can do so by GOTO 9945 followed by CENTER),
One interesting use of this model ls to define a REM
statement containing the message which you want to
display e.g. 10 REM Copyright (c) Beam Software
Then you can renumber this line to 0 by specifying
the NEW LINE # as 0,
After the renumbering you can no longer access this
line 0 again unless you use the renumbering program to
change the line to any number greater than 0 „
104
Space Escape
RENUMBERING MODEL i
^990 REM
9991 LET L = 100 ’ LET N = 23755
9992 IF *256* PEEK N+ PEEh *N+1)) >= 9990
THEN STOP
9993 POKE Nx IN! (L/256)
s POKE (N+1J. L- INT <L/256>*256
9994 LET L ~ L+10
s LET N — N+3+ PEEK {N+2>+256* PEEK <N+3)+l
9995 GO TO 9992
RENUMBERING MODEL 2
99BB LET NEW - 100 * LET INC == 10
i LET BOB = 100 * LET EOB = 9980
9989 LET L — NEW - lET N = 23755
9990 IF <256* PEEK N+ PEEK iH+l )> >= BOB
THEN GO TO 9992
9991 LET N = N+3+ PEEK (N+2J+256* PEEK (N+3J+1
i GO TO 9990
9992 LET nl = *256* PEEK N+- PEEK tN+l)J
- IF nl EOB THEN STOP
9993 POKE N, inT (L/256>
9994 pi>£ N+l, f_~256* INT <L/256>
9995 FOR I = N+4 TO N^3+ PEEK *N+2)+256* PEEK (N+3)
9996 IE PEEK I « 236 OR PEEK I = 237
THEN PRINT L= CHR$ PEEK I
9997 i9£ yj j
V99S LET N = I - LET L = L+INC
9999 &0 JO 9992
♦
105
RENUMBER MODEL 3
7900 REM
9901 REM Renumber^program
9902 LET BOB = ICO J LET EOB = 8999 ?
LET INC = 10 * LET NEW = 1O0
9903 BORDER 7 * PARER 7 = INK 1 = CLS
9904 PRINT AT 0, 7; INVERSE 15 *"L INE * RENUMBER ^MENU"
9905 PRINT AT 2, 17; INVERSE 15 "CURRENT"5 AT 2, 28:
INVERSE 1; ** NEW' 1
9906 PRINT AT 4, 05 “BtflrtinqUine.#"
9907 PRINT AT 4, 18+4- LEN t STRt 808)5 BOB
9908 PRINT AT 6, 0; l, Ending iii hne i #"
9909 PRINT AT 6, 18+4- LEN < STRt EOB); EUB
9910 PRINT AT 8„ O?
9911 PRINT AT 8, 18+4- LEN i STRt NEW); NEW
9912 PRINT AT lO, O; “ I ncr em&nt ,l
9913 PRINT AT lO, 18+4- LEN l STRt INC) 3 INC
9914 PRINT AT 14, 4; INVERSE 1;
"Press^ENTER^if,nD + change”
9915 REM input t parafi>eter
9916 PRINT AT 4, 26: FLASH 15 INVERSE 15 > *‘5
FLASH O: INK 2? " ****'■
9917 INPUT St i IF S* = ,,u THEN GO TO 9919
9918 LET BUB = INT t VAL St+.5>
9919 PRINT AT 4, 265 ”*”5
AT 4, 27+4- LEN < STRt BDB>5 BUB
9920 PRINT AT 6, 265 FLASH l; INVERSE 15 " > "5
FLASH O; INK 2; "***„'"
9921 INPUT St i IF St - " ,J THEN GO TO 9923
9922 LET EOB = INT ( VAL St+.51
9923 PRINT AT 6, 26; «
AT 6, 27+4- LEN ( STRt EOB); EOB
9924 PRINT AT 0, 26; FLASH l; INVERSE i; » ,
FLASH 03 INK 2; "
9925 INPUT St * IF St = "" THEN GO TO 9927
9726 LET NEW = INT < VAL St+.5)
9927 PRINT AT 8, 265 “*"5
4 AT 8, 27+4- LEN < STRt NEW)? NEW
9928 PRINT AT 10, 26; FLASH 11 INVERSE l; > "!
FLASH 0 3 INK 21 "****■'
9929 INPUT St s IF St “ ”" THEN GO TO 9931
9930 LET INC = INT i VAL St+.5>
9931 PRINT AT K>, 26;
AT 10, 27+4- LEN ( STRt INC); INC
9932 FOR I = I TO 50 * NEXT I
9933 REM +ind*f irst ^number
9934 LET N = 23755
9935 IF 2564 PEEK N+ PEEK <N+1) >= BOB THEN
00 TO 9937
9936 LET N - (N+3+ PEEK <N+2>+256* PEEK (N+3)+l) -
GO TO 9935
9937 CLS * PRINT AT O, 1H FLASH l; INK 2; INVERSE I
"RENUMBERING"
9938 GO SUB 9991
106
9^39 PRINT AT O. 11 i INK 2; INVERSE
” _ iF INISHEJD * "
9940 INPUT *'.*to A ©x it* ,M *z ,M, *tn
*copy ^screen * A Any *kBv *to *cont i nue* "s S$
9941 IF 5* = 11 z 11 THEN COPY ; £0 TO 994t>
9942 IF S* < > "I” THEN 00 TQ 9903
9943 INPUT " ”d '*" * to * de 1 et e ^pr ograu!
******* *Any *key ^to *e* i t * f1 ;
k*
9944 IF ** <;> ’‘u- THEN STOP
9940 LET N = 2-3705
^946 IF 2064 PEEK N+ PEEK 04*1) >= 9900 THEN
GO TO 9940
9947 LEI N = ',14+3+ PEEK <N*2)*256¥ PEEK CKH-3>+l) ~
GO to 9946
9943 LET DA ~ N+2 ± LET DL = -4
9947 LET n1 = PEEK (N+2/+256* PEEK fN+3> *
LET DL = DL+nI+4
9900 LET n2 « <206# PEEL N+ PEEK (N+15) s
IF n2 < 9999 THEN LET N « M+3+nl+l =
GO TO 9949
9^01 LET ni = INT iDL/206) - &LLJ O POKE CDA+1), nl
POKE DA, DL-ftl*256 * POKE (DA+2>, 234
9952 PRINT AT 21, 0; "Type."; FLASH l;
"9900* ENTER > ” \ FLASH 0; " *tO*del eie"
9953 STOP
QQ9j LET L = NEW
9992 IF <256* PEEK N+ PEEK (N*l )> > EQB THEN RETURN
9993 POKE N, INT CL/256)
^994 POKE N+JL - L-256* INT CL/256?
9965 FOR l = N+4 TO N+3+ PEEK <N+2>+256* PEEK <N+3>
9^96 IF PEEK I - 256 OR PEEK I = 23T THEN FRINT L%
"“"5 CHR* PEEK 1
o?fl7 NEXT I
999S LET M - I i LET L - L+INC
9999 SO TO 9992
107
Block Line Delete
Copyright (c) Beam Software
DESCRIPTION
This is another UTILITY program which any SPECTRUM
BASIC programmer will find useful at program devclopement
stage*
If you have read the RENUMBERING program in this
book, you will notice that this BLOCK LINE DELETE program
is particularly useful to delete the renumbering program
at the end of its operation.
Besides that, this program will delete itself as
well *
Again, screen handling techniques are used to input
starting line block and ending line block to be deleted;
the program is SMART enough to delete all lines with
numbers greater than or equal to the starting line block,
smaller than or equal to the ending line block. So, even
if your input line block number does not exist, it won't
CRASH the program.
To use the program, first of all, you must enter the
starting and ending line number of the block you wanted
to delete. Notice that you can delete one line by having
the same starting and ending line number. After the
program finishes its house-keeping function, the program
will prompt an instruction to ask you delete the line
block by typing the starting Line number followed by
(ENTER).
PROGRAM STRUCTURE
The algorithm used in the program counts all bytes
from the memory after the line length location of the
starting line to the end of line character of the ending
linef This byte-length value will then be POKEd into the
starting line length location and the first byte content
of that line will be changed to 23A ( REM ); In effect,
the whole line block is converted into a single REM
statement. Therefore, re-entering the starting line
number with empty content will delete the whole line.
The structure of the program is as follows t
INPUT LINE BLOCK NUMBER to be deleted
DISPLAY REFORMATING message
FIND STARTING LINE MEMORY LOCATION
REMEMBER LINE LENGTH LOCATION and INITIALISE NEW
LENGTH
COUNT byte-length UNTIL END OF BLOCK
POKE byte-length INTO STARTING LINE LENGTH LOCATION
DISPLAY FINISHED message
DISPLAY FINAL message instruction
SPECIAL NOTES
After the REFORMATING process has Finished, if you
don't retype the starting line number with an empty
string, you can still reference any line within the block
except the starting line. Any future reference of the
starting line will delete the whole block*
It is then advisable to save your program before you
delete any part of it using this BLOCK LINE DELETE
program in case you delete the wrong block.
You have to MERGE this program with your own program;
don't use LOAD as this will destroy your program in the
LOADing process.
Si-OLk line delete
9973 REM
9974 REM B^UCK*LINE ^DELETE
9975
OVER
0 -
PLASH
0 i F AF ER 7
- INK t ± CLS
997B
PRINT
AT
0 * 8 i
INVERSE I;
"BLOCK *LINE„DELETE"
9977
PRINT
AT
4, 0;
"DELETE * INCLUSI VEL Y 11
9978
PH I N I
AT
6 , 9;
"FROM*LINET
9979
F RIN T
AT
Bt 9;
M rtn^LINE"
;
99R0
PRINT
AT
6 , 19;
FLASH 1: "
' "| FLASH 05 INK 2
INVERSE 13 “****'♦
9981 INPUT £* : IF VAL S* O OR VAL 6* 9972 THEN
GO TO 9*81
9982 LET SOD * INI I VAL S*>
9983 PRINT AT t», 19: " *,***•■ i AT h*
20+4- LEM { 5TR* SOD>; SOD
9984 PRINT At 8* 19; FLASH I ; 11 11 ; FLASH 05
INK 25 INVERSE l; "****•'
9985 INPUT 5* - IF VAL S4 O OR VAL 99?Z iHEN
80 TO 99S5
99BB LET EOD = LNT < VAL S* )
9987 PRINT AT 6, 19; H *****“; AT 6,
20+4- LEN ( STR$- EOD) ; EOD
9980 PRINT AT ii, 105 FLASH 1; INI 2; INVERSE i;
*•*REFORMAT I NG 1 "
9989 LET N = 23755
9990 IF 25fe* PEEK N+ PEEK <N+1> >= SOD THEN
SO TO 9992
9991 LET N = <N+3+ PEEK <N+2)+256* PEEK <N+3)+l) t
SO TO 9990
9992 LET DA = H+2 = LET DL = -4
9993 LET nl = PEEK KN+2)+25e* PEEK (N+3> s LET
DL = DL+nl+4
9994 LET n2 = 1256* PEEK M+ PEEK. cN+i)j i IF
n2 < EOD THEN LET N - N+3+nl+l * SO TO 9993
9995 IF n2 > EOD THEN LET DL = DL-ril-4
999/> LET ni = INT <DL/25t> s POKE tDA+1). nl : POKE
DA, DL-n 1*256 * POKE <DA+2I, 234
999^ PRINT AT 11, LOS ,s * * .* ^ ^ ^ * ***;
AT 11, 12S INI 2; INVERSE i; "FINISHED-’*
9990 PRINT AT 15, 0; “TYPE * " 5 FLASH Ii SOD;
“ < ENTER ■ i FLASH 0 5 MO *DELETE * BLOCK"
9999 STOP
no
Machine Cede Monitor
Copyright <c) by Beam Software
In a few programs in this book we refer to machine language
programs as being more efficient* and in some cases we show
you examples of how writing programs in machine language can
speed up execution time* and also save on memory.
You may therefore be asking yourselves what is the machine
language these notes refer to? What is the difference between
machine language and BASIC?
to set the scene correctly* you must accept first of all
that the Spectrum does not really ever execute your BASIC
program. In fact* the chip that does all the work* the Z80*
doesn’t even understand BASIC. All it can understand is its
own set of instructions; and limited instructions at that.
The range of instructions the Z8G understands comprises oE
such simple things as add two numbers, subtract* compare,
take a number from here and put it there* and so on.
Admittedly most things can be achieved with these simple
functions.
But even slightly more complex functions, simple by our
standards* such as multiplication and division cannot be
executed as such. You have to write a program to perform
these tasks.
Your Spectrum computer comes inbuilt with a machine
language program* This progam is stored in a chip inside the
computer so that it does not have to be loaded from tape each
time you want to use it. This program is In the ROM chip (ROM
stands for Read Only Memory, which means you can't change
it).
The ^function of this program is to take the information you
give the computer via the keyboard and perform the
Instructions necessary to obtain the result you desire. A
simple BASIC line may require hundreds of lines of machine
language program to do its task.
You can understand that BASIC while being a much mare
efficient means of programming (one line instead of hundreds)
probably results in slower execution of programs.
The program provided here does not pretend to teach you
machine language* Whole hooks have been devoted to this
subject, and we can certainly recommend two of our other
titles if you are interested in this topic:
* Spectrum Machine Language For The Absolute Beginner
* Understanding Your Spectrum by Dr. Ian Logan
111
The structure of machine language programs:
Machine language programs are. structured differently from
BASIC programs in several ways. Some of these are important
in this context:
~ There are no variables
There is no direct equivalent to LET lives = 3
All there is as far as the Z8Q is concerned are
memory locations*
If you check your Spectrum manual you will find
on pages 173 - 176 a list of memory locations used
as variables by the program in the ROM.
You can change the value held in those locations
to achieve different effects, and to signify
different things, but that is the limit of the
analogy to variables*
* There are no line numbers
When executing instructions the Z80 will go from
one instruction to the next, exactly as it finds
them.
Admittedly there are instructions that allows you
to instruct the ZSQ to GOTO another instruction or
to GQ5UB another set of instructions, but these
GOTOs and GOSUBs are specified in terms of memory
locations also - eg* one instruction might be "GOTO
the instruction at memory location 16’ 1 *
This means that in general, programs are designed
for very specific memory locations*
Some programs however are relocatable, and we
discuss these later.
* All numbers used are either in the range 0 - 255 or
0 - 65535, (depending on whether they occupy one
memory location or two!)
In other words the number occupying a single memory
4 location can only be in the range 0 - 255. Because
of this a special notation has been developed,
that efficiently describes numbers in the range
0 - 255.
This is called Hex (or hexadecimal) notation.
This book is not the place to explain this notation
but you will find a conversion table from Hex to
decimal in the Spectrum manual on pages 183 - 188,
What is PEEK and POKE?
Now that you have a slightly better understanding of way
the Spectrum functions, you understand that there can be no
simple equivalent to LET a = b.
The closest equivalent is to think of a and b not as
112
variables, but as the contents of different locations. Given
this equivalent, how can we find out what are the different
memory locations?
The BASIC instruction PEEK lets us do exactly what Its name
suggests - we can PEEK into a memory location to find out
what is there. Furthermore, a PEEK does not disturb what is
there. We can PEEK to our hearts' content without doing any
damage or disturbing anything.
So we can now at least find out what b is. Remember though
that looking in a single memory location will give an answer
in the range of 0 to 255 only.
How can we now change the contents of another location? We
can POKE it. This instruction is again very much like what it
sounds. You take what you want to fill the memory location
with, and you POKE it in. As well, just as the name suggests,
this is a rather rude and final instruction - you POKE a
value in and it stays there. The potential damage you can
wreak in programming terms Is immense.
Do not be hesitant to use this instruction however, and to
experiment with it. The worst you can do is to crash your
program, or to have the Spectrum reset itself. There is no
way you can damage the computer itself by POKEing anything
anywhere *
Remember though that you can only POKE values in the range
0 - 255.
Hex notation:
You may have had a look at pages 183 - 188 of your Spectrum
manual and seen the column of Hex numbers.
Certain things about this notation stand out:
Each number is always 2 characters
Only the numbers Cl - 9 and letters A - F
are allowed.
These two points are in fact the major benefits of Hex
notation.
Each of the letters A to F represents the numbers 10
through to 15,
To convert from Hex notation to decimal, take the number in
the 'tens column 1 , multiply it by 16 and add the number in
the 'ones column'. Thus:
OA Hex - 10 decimal
11 Hex - 17 decimal, etc.
113
The Machine Code Monitor Program;
This program enables you to examine the contents of any
memory location in the Spectrum, whether in the ROM or in the
RAM (that's the 'normal 1 memory, including the screen,
program area, variables, free memory and user defined
graphics area).
It is not the most efficient program if you wish to PORK a
lot of data into a memory area, but it is very good if you
wish to examine any part of memory and modify it. To enter a
lot of data into memory see some of the other programs in
this book, such as in the Draughts program.
Each line of the display shows the contents of 10 memory
locations, with the contents shown in Hex format. You can use
the arrows keys (Shift 6 to S) to move the cursor around.
Pressing any key other that the arrow keys will allow you
* to change the contents of that memory location. The value you
enter must be in Hex format. Remember that only the numbers 0
- 9 and letters A - F are allowed and that a valid number is
made up of exactly two characters*
Some interesting exercises:
* Try to modify the contents of memory locations in the ROM.
(Addresses below 16384), What happens?
* Try to modify the contents of memory locations in the range
22528 to 23295,
This is the "attributes" area, which defines what colours
show up on the screen. You cannot damage the program or the
computer.
* T n> to modify the contents of memory locations 16384 to
22527.
This is the screen display memory area.
Remember that each character space on the screen requires 8
memory locations in the screen display area to define It* The
eight memory locations are not consecutive. Can you find out
how these 8 memory Locations are related to each other?
You cannot damage the computer or the program doing this.
Relocatable Machine Language Programs:
There are some machine language programs which are said to
be relocatable. This means that it is not important where in
memory they start.
Such programs are obviously very useful when used as
adjuncts to BASIC programs, because it means we can POKE them
anywhere there is free space.
114
One example is the screen movement routine in the
Eliminator program contained in this book.
Here we give you another useful relocatable machine
language program, this time a renumbering program. You will
note that compared to the BASIC renumber programs listed
elsewhere in this book, the machine language version is much
shorter (only 27 bytes long!) and you will find It is also
very much faster.
To ’’load’ 1 the program into memory, we need a short BASIC
program as listed, or you could enter the bytes into memory
through the machine code monitor program. (The Hex values arc
in the left column of the assembly listing given.)
Once the numbers have been PGKEd into memory it is a good
idea to save the program on tape, using the SAVE ,TrT CODE
command.
To "run" a machine code program, the USR function is used,
such as PRINT USR 32500, or LET v = USR 32500. The number
after the USR must be the address where the machine code
program Is.
Be sure to always place your machine code program in a area
that cannot be overwritten - eg above CLEAR, or in the user
defined graphics area, etc.
The machine code program given here renumbers all lines,
starting with Line 100 and incrementing in steps of 10. You
can change the starting number by changing the 5th number
(currently 90 - 100 - 10) and the step by changing the 13th
number (currently 10), Note that it does NOT renumber GOTOs
or GQSUEs,
Assembly listing for machine code renumber program:
4
11
CA
5C
LD DE, 5CCAH
;start of BASIC
21
5A
00
LD HL, 90
;start no# - step
13
nxtUne INC DE
1A
LD A, (DE)
;what ( s there?
FE
28
CP 28H
lend of line ?
DO
RET NC
;if not, finished!
01
OA
00
LD BC, 10
; step siaje
09
ADD HL,BC
;new line no.
EB
EX DE, HL
itemporary swap
72
LD (HL), D
;put new line no in
23
INC HL
73
LD (HL), E
23
INC HL
;get length of line
4E
LD C. (HL)
;put it in BC
23
INC HL
46
LD B, HL
09
ADD HL, BC
;posn of end of line
EB
EX DE, HL
;end of swap
18
EB
JR nxtlin
;do next line
115
MACHINE CODE MONITOR
100 PRINT INK 7 3 PAPER 25 AT 0 5 O; "MACHINE jXODE
* MON I TOR ****. J *.i*'*
110 INPUT *'P1 ease^enter ^starting ^address
* * a < 1 n *dec i mal ) * " 3 s
120 LET s = 10* INT <s/10>
130 LET x = O t LET y = O
140 60 SUP 1000
150 PRINT INK 7 3 PAPER 2 3 AT 0* Oi "MACHINE*CODE
^MQNI TOR_***"
160 PRINT OVER 1? FLASH i; AT 3+2**, 3+3*yi
170 LET a* == INKEY*
180 IF CODE a* < 12 AND CODE a* > 7 THEN GO TO 600
190 IF CODE a* = O THEN EG TO 170
200 INFUT "CHANGE ^BYTE ^VALUE *TO* (Hex ) '* J a*
210 IF LEW a* <> 2 THEN GO TO 160
220 GO SUB 500
230 IF v < O OR v > 15 THEN GO TO 170
240 LET h = v
250 LET a* » a*<2>
260 GO SUB 500
270 IF v C 0 OR v > 15 THEN GO TO 170
280 LET L - v
290 LET v = 16*h+L
300 POKE s+lOIx+y, v
310 PRINT OVER 1$ FLASH OS AT 3+2*x , 3+3*y3
320 IF y = 9 THEN GO SUB lOOO
330 LET y = y+i
340 IF y > 9 THEN LET y = O * LET w = x + 1
350 IF x < 10 THEN GO TO 140 * REM elsestalls
^through *tq*next*page
360 GO TO 730
500 LET V = CODE **-40-7*< CODE aS > 64)
-32* ( CODE a* > 96)
510 RETURN
600 PRINT DVER 13 FLASH 05 AT 3+2*x s 3+3*y;
610 GO TO 540+10* CODE a*
620 LET y = y—1 i GO TO 660
630 LET y =* y+1 s GO TO 700
640 LET x = x + 1 5 GO TO 730
650 LET x = x-1 i GO TO 680
660 IF y >= D THEN GO TO 160
670 LET y = 9 s LET x = X-l
680 IF x >«* O THEN GO TO 140
690 LET s = s-10 s CLS ? GO TO 130
700 IF y < 10 THEN GO TO 160
710 LET y ^ O i LET x = x+1
720 IF X < lO THEN GO TO 140 * REM else*4alls
*through ^to *next *page
730 IF x - 10 THEN CLS s LET s = s+iO*x ± GO TO 130
740 GO TO 140
1000 IF s < 0 OR 5 > 65530 THEN GO TO 110
1010 PRINT AT 2+2*x, 05 s+10*x * PRINT TAB 2?
1020 FOR i = s+lO*x TO s+10*x+9
116
1030 IF i > 65535 THEN LET i » s+10*L+9 * GO TO ISO
1040 LET v = PEEK i ; LET h = INT <v/l6) *
LET L = v—16*h
1050 PRINT " -l m + CHR* <h+4B+7*(h > 9U +
CHR* (L+49+7*(L > 9)35
1060 NEXT i
1070 RETURN
Machine code Renumber
100 CLEAR 32500 * LET a * 32500
110 READ n * POKE a, n
120 LET a = a+1 * GO TO 110
130 DATA 17, 202, 92, 33, 90, O, 19, 26, 254, 40,
20B, 1, 10, O, 9, 235, 114, 35, 135, 35, 73,
35, 70, 9, 235, 24, 235
140 FOR i - O TO 26
150 PRINT PEEK <32500+1>; "^"3
160 NEXT i
117
Payroll
Copyright (c) Beam software
DESCRIPTION
This payroll worksheet will calculate employee income
and produce a check register that may be used to produce
paychecks,
The register begins with the option of
EITHER entering the NAME of the employee and his/her
hourly rate, the overtime factor. An option ls
given If you want to save these EMPLOYEE
DETAILS onto tape
OR you can restore the stored EMPLOYEE DETAILS
from previously saved tape
At the end of each pay period, you enter each
employee's hours ( regular and overtime ). The
MINI-PAYROLL model will calculate gross income for all
employee.
This PAYROLL model can only cater for a maximum of 18
employees. But for any small size business operation,
this will surely save either you or your secretary a lot
of time in calculating wages.
The whole model is screen driven, with appropriate
flashing cursor indicating which field the program is
expecting to receive, AM numeric data input or output
will be right justified.
At the end of all input and calculation, any key
press will bring you to the next major three screens of
the model in the following order:
Employee details
Hourly payroll register
Wages payroll register
The wages calculation is correct to the nearest
pence.
PROGRAM STRUCTURE
This program is one of the three SPECTRUM financial
models in this hook. One major difference of this type of
program from games or utilities is that INPUT/OUPUT must
be done in a USER FRIENDLY way. In term of processing*
you will find that It is mainly string manipulation and
calculation.
118
The structure of the program is as follows:
INITIALISATION
INITIALISE ENTER MODE OF THE THREE SCREENS
INITIALISE DISPLAY VARIABLES
EMPLOYEE DETAILS
TF T E' OR ’ e 1 ( enter new information )
input number of employee ( between 1 and 18 )
define dimension of following ARRAY*
E$ Employee details array
R$ Regular hours array
0$ Overtime hours array
G$ Gross income array
IF T R’ OR f r* ( retrieve information )
input EMPLOYEE DETAIL from tape
define dimension of above arrays except E$
I: SET UP EMPLOYEE DETAIL SCREEN
IF KM MODE IS ENTER (rm=0)
set rmsl
input employees name and hourly rate
input overtime factor
save EMPLOYEE DETAILS options
return
REDISPLAY EMPLOYEE DETAILS
option of sending the display to printer
return
PAYROLL hourly register
SET UP PAYROLL HOURLY REGISTER SCREEN
IF PM MODE IS INPUT (pm=G)
set PM mode to display Cpm-1)
input regular and overtime hours
return
REDISPLAY PAYROLL HOUR REPORT
option of sending the display to printer
return
PAYROLL gross income register
IF PR MODE IS CALCULATE (pr=0)
set display mode (pr=l)
initialise TP (total gross wages)
calculates and adds up all employee wages and
enters into corresponding arrays
SET UP PAYROLL INCOME REPORT
REDISPLAY PAYROLL INCOME REPORT
option of sending the display to printer
return
119
MAIN LOOP
EMPLOYEE DETAILS
LI: PAYROLL hourly register
PAYROLL income register
GOSUB 11 *
GOTO LI:
SPECIAL NOTES
The EMPLOYEE DETAILS array is structured as follows;
* first record
1-5 number of employee records in the
array
16- 21 overtime factor
* following records
1-15 name of employee
16- 21 hourly rate of the employee
You will notice that there are three major arrays
each having mainly two tasks to performed, namely,
display and input/caiculation.
To choose which task to be performed, the program
first sets three mode variables to input/caleu 1 ation (le
0) at the beginning and these in turn will be set to
display (ie 1) mode after each routine gone through their
input/ealculation task.
From this time onward, further re-entry to the array
will result in the performing of display task*
Routine 3000 performs the task of the conversion of
any string numeric input with number of digits before the
decimal point specified to a numeric string of that
specified number of digits before the decimal point and
two digits after the decimal point*
120
PAYROLL
IOO REM PAYROLL
ilG REM mi ni *payrol 1 ^program
120 LET rm = O s LET pm *= rm ± LET pr — rm ‘
REM set*enter*mode
1-30 OVER 0 - PAPER 7 ± INK 1 * FLASH O - CLS s
GO TO 9000
1000 REM
1010 REM mitialise^routine
1020 CLS i PRINT AT O, 61 INVERSE l; INK l;
"EMPLOYEE * INFORMATION"
1030 PRINT AT 6* 15 INK 15 "ENTER A new
information *™*E"
1040 PRINT AT B, l; INK 15 "RETRIEVE**information
— *R"
1050 PRINT AT 15, 8? INK 1 5 "Press*" 11 " 5 FLASH l;
"E" ; FLASH 0 5 .*or .* '* *' " 5 FLASH I 5 "R" 3
FLASH 0; """"
1060 LET EXT &jii Ok* = INKEY* ± IF k* <> "E" AND
k* <> "fi M AND k* <> 11 e" AND k* <> ‘V"
THEN GO TO 1060
1070 IF k T — "e" OR k* ** "r" THEN LET k* = CHR*
C CODE k*—32)
1080 PRINT AT 15* 15; INK l; INVERSE l; "E"5
AT 15* 225 "R" s PRINT AT IS, 12;
1090 IF k* <> "R" THEN GO TO 1150
1100 PRINT INVERSE 15 INK 2; “RESTORE"; i LET rm * 1
1110 INPUT "Press* < space > < ENTER > *when*ready
" 5 k*
1120 IF k* <> THEN GO TO 1110
1130 LOAD "minipay" DATA E*O
1140 LET NE = VAL E*<1, 1 TO 2) * LET F = VAL
E*(1, 15 TO 21) * GO TO 1190
1150 PRINT INVERSE 1| INK 2; 'RENTER*" * PRINT
AT 21, 2; INK i; INVERSE 1; FLASH 15
FLASH o; INVERSE 05
** no, *emp 1 oyee * < 1 *- * 18) * * * " ;
INVERSE li
1160 iPlPUT NE i IF NE > 10 OR NE < 1 THEN
GO TO 1160
1170 PRINT AT 21, 30; '***"; CHR* 8; CHR* S; INK IS
INVERSE 1; NE
1190 DIM E* i NE +1, 21>
1190 DIM R*<NE, 6>
1200 DIM 0*(NE, 6)
1210 DIM G* fNE, S>
1220 FOR I = 1 TO 75 * NEXT 1
1230 INK 1 ‘ PAPER 7 s CLS = PRINT AT O* 9;
INVERSE 1 Ext SHI Of "EMPLOYEE*DETAILS"
1240 PRINT AT 2, 25 INVERSE li "NAME *OF ^EMPLOYEE" 5
AT 2, 215 "HOURLY *RATE"
1250 IF rm = l THEN GO TO 1500
1260 REM enter*emp1oyee^details
1270 LET rm = 1
1280 FOR I = 2 TO NE+1
1290 LET E* <I, 1 TO 15) = "* M s LET E* < I, 16 TO 21)
= " 000000 "
121
1300 LET Ln = 1+3-2
1310 PRINT AT Ln, 1J s IF I > 10 THEN PRINT AT Ln, Qi
1320 PRINT 1-1; FLASH U INVERSE l; H > “i AT Ln, 3;
FLASH 0? INK 2; " * * *„„,, **-.
1330 INPUT S* i IF St = “T 1 THEN RETURN
1340 LET E*U, t TO 15) = S* * PRINT AT Ln, 2?
,1 * n f EHI, 1 TO 1ST
1350 PRINT AT Ln, 20; INVERSE l; FLASH 1; " > " i
AT Ln, 23; FLASH 05 INK 2; ■■**„**"
1360 INPUT SI J IF VAL S* < O THEN GO TO 1360
1370 LET ns “ 3 ^ GO SUB 3000 * REM input*nU»eric
5*
string
13S0 PRINT AT Ln, 20 5 "* ,J 5 AT Ln, 233 M
AT Ln, 23J S*> * LET E* (I , 16 TO 21)
1390 NEXT I
1400 PRINT AT 21, 9; INVERSE l; "Over t i me * factor " 5
AT 21, 25I FLASH l; " > " ; FLASH O? INK 2;
AT 21, 27; "*****"
INPUT S* t IF VAL S* < O THEN GO TO 1410
= VAL 5* t PRINT AT 21, 25; ■**„„**" i
25; F ~ LET E*(l, 16 TO 21) * S*
- 5TR* NF
1410
1420 LET F
AT 21,
1430 LET E*U,
1 TO 2)
k %
1440 FDR I = 1 TO 50 5 NEXT I
1450 INPUT “Save^EMPLOYEE^DATA*?^ (yes*or .no) " ;
1460 IF k$ = " " THEN GO TO 1450
1470 IF = "y" OR k* = " Y" THEN SAVE "mini pay"
DATA E*() ; RETURN
1480 IF kfU) <> "n" AND k*a>. <> "N Ji THEN GO TO 1450
1490 RETURN
1500 REM rsdisplay*employee^record
1510 LET NE - VAL (E*(l, 1 TO 2)) = LET F =
VAL (E* <1, 16 TO 21) )
1520 FOR 1=2 TO NE+1
1530 LET Ln = 1+3-2
1540 PRINT AT Ln, 2i E* Cl, 1 TO 15); AT Ln, 23;
E*<I, 16 TO 21)
1550 NEXT X
1560 PRINT AT
" OVERTIME ^FACTOR “
M, 9; INVERSE
1570 PRINT AT 21, 25; F
1580* LET k$ = INKEY* ? IF k* - " M THEN GO TO 1500
1590 IF k* = "z" THEN COPY i SO TO 1580
1600 RETURN
2000 REM
2010 REM enter/displ ay A payrol I *hour
2020 CLS i PRINT AT O, B; INVERSE li "PAYROLL*REGI5TER"
2030 PRINT AT 1 # 17; INVERSE H M -*HOURS^—- if
2040 PRINT AT 2, 05 INVERSE l; "EMPLOYEE"5 AT 2, 19;
"REG"; AT 2, 27; H 0T"
2050 IF pm = 1 THEN GO TO 2500
2060 LET pm =1 ± LET TR = O s LET TO ^ TR
2070 FOR I = 2 TO NE+1
2080 LET Ln = 1+3-2
2090 PRINT AT Ln, O; E*CI, 1 TO 15)
2100 PRINT AT Ln, 16; FLASH IS " > " S FLASH Q| INVERSE 1
INK 25 “**„**■’
2110 INPUT n1 t IF nl < O THEN GO TO 2110
2120 LET S$ = 5TR* nl - LET ns = 3 * GO SUB 3000
2130 PRINT AT Ln, 16; " ; S* * LET TR -
TR+nl s LET R*(I-1> - S*
122
2140 PRINT AT Ln, 24; FLASH I; &U1 O" > “;
FLASH 0; INK 21 INVERSE 15 “******"
2150 INPUT nl s IF nl < O THEN GO TO 2150
2160 LET S$ - STRS nl i LET ns - 3 * SO SUB 3000
2170 PRINT AT Ln, 24; '**"1 S*
21BO LET TO = TO+ni - LET □*{!-!> = SS
2190 NEXT I
2200 LET S* = STR* TR * LET ns = 4 s GO SUB 3000
2210 PRINT AT 21, 9; INVERSE l; "TOTALS"; AT 21, 16;
INVERSE O; S*
2220 LET SS = STRf TO s GO SUB 3000
2230 PRINT AT 21, 24; S*
2240 RETURN
2500 REM displ ay*hour*report
2510 FOR I = 1 TO NE
2520 LET Ln = 1+3-1
2530 PRINT AT Ln, O; E*<X+1, 1 TO 15>i AT Ln, 17;
R*(I, 1 TO 6)i AT Ln, 25; O* < 1, 1 TO 6>
2540 NEXT I
2550 PRINT AT 21, B; INVERSE 1; “TOTALS"
2560 LET S* = STR* TR - LET ns — 4 s SO SUB 3000
2570 PRINT AT' 21, 16; S*
25B0 LET S* = 5TR* TO ± GO SUB 3000
2590 PRINT AT 21, 24; 5*
2600 LET k* = INKEYS * IF fc* = THEN GO TO 2600
2610 IF k* ** ,i z H THEN COPY i GO TO 2600
2620 RETURN
3000 REM
3010 REM string^inputiValue
3020 LET T* ■ STR* ( INT VAL S*>
3030 FOR J = 1 TO (ns- LEN T*) s LET T* - "*“+T* s NEXT
J
3040 LET U* = STR* ( INT (< VAL S*- VAL T*)*300+«5)> =
LET
7 * = T*+", 11
3050 IF VAL US = O THEN GO TO 3090
3060 FOR J = 1 TO LEN U* s IF U* (J TO J1 - % * # THEN
GO TO 3080
3070 NEXT J
3080 LET U* = U*<1 TO (J-l)>
3090 IF VAL U* < lO THEN LET U* = "0"+0#
3100 LET S* = T*+U*
3110 RETURN
4000 REM
4010 REM calculate/display *pay
4020 IF pr = 1 THEN GO TO 4100
4030 LET pr = 1 s LET TP - 0
4040 FOR I - 1 TO NE
4050 LET nl = t VAL R*U>+ VAL D*<I>*F>*( VAL
E* (1 + 1, 16 TO 21)>
4060 LET S* = STR* nl s LET ns = 5 * GO SUB 3000
4070 LET G*<I, 1 TO 0) = S*
4000 LET TP - TP+nl
4090 NEXT I
4100 CLS ‘ PRINT AT O, B; INVERSE 1;
"PAYROLL * REGISTER“
4110 PRINT AT 2, O; INVERSE U "EMPLOYEE"5 AT 2, 21;
"GROSS^PAY"5 AT 3, 19;
4120 FOR I - 1 TO NE
123
4130
4140
4150
4160
4170
4180
4190
4200
4210
*3000
9010
9020
9030
9040
9050
9060
LET Ln * 1+3-1
PRINT AT Ln, O; E*U + 1, 1 TO 15); AT Ln, 225
G*<I, 1 TD 81
NEXT I
PRINT AT 21 * 7; INVERSE l 3 "TOTAL * WAGES*' 5
AT 21, 19 5 INVERSE 0 3
LET S* - STR* TP * LET ns - 6 ; GO SUB 3000
PRINT 5*
LET kS - INKEY* s IF kt = "" THEN GO TO 4190
IF fc* = "2" THEN COPY t GO TO 4190
RETURN
REM
REM main^routine
GO SUB 1000
GO SUB 2000
GO SUB 4000
GO SUB 1230
GO TO 9030
REM initialise
REM payrolI*register
REM display/calculate*pay
REM payroll ^record
Sales Analysis
Copyright (c) by Beam Software
This program uses a company's sales history over a number
of years to determine what seasonal fluctuations occur in
that business's sales, and what the overall trend has been
for that number of years*
The results of this program would be useful to any company
or sales manager of any company whose business is affected by
seasonal fluctuations* for example, in book publishing, about
2TL of annual sales occur in November and December*
The information required hy the program Is the sales value
in each quarter for as many years as are available. As
written, the program can only accept information for a
maximum of 18 years.
After this information has been entered, the program will
calculate seasonal ratios by dividing the actual sales by the
average quarterly sales for all years.
The average of each quarter's ratios over the years
produces the seasonal index.
The program will also chart in graph form the annual sales
of the company, providing immediate visual information about
the company's growth.
Programming notes:
As with the other business programs presented in this book,
a high emphasis has been placed on the interaction between
the user and the computer. It is generally true that business
programs must be able to be understood and be useful to
people who have no knowledge of computing.
Screen-driven data entry is the name given to the
input/output used in this program. The main benefit of this
is that the user has immediate verification of what he has
entered and the amount of information entered.
The results are displayed on two screens - one containing
the actual sales, and the other the seasonal indices.
Pressing any key allows you to switch back and forth between
the two screen. An additional option allows sending the
screen display to the printer.
The graphical display makes use of the Spectrum's PLOT and
DRAW facilities. The sales history screen is used, with the
only the year and the average quarterly sales left on the
screen. By using the minimum and maximum sales over the years
to define the axis scales, the graph makes use of the entire
display area available*
125
SALES ANALYSIS
100
t 10
120
10Q0
1010
1020
1030
1040
1050
1060
1070
1090
1090
1100
1110
1120
1 130
1140
1 150
1160
1170
1172
1174
1180
1190
1200
1210
2000
2010
2020
2030
2040
2050
2060
2070
2080
2090
2100
21 10
2120
2130
2140
2150
REM
REM SEASONAL*INDEX
BORDER 7 * PAPER 7 * INK 1 s FLASH O - OVER
O * CLS 130 GO TO 8000
REM
REM input^year^range
PRINT AT O, ?; INVERSE 15 "SEASONAL * INDEX '*
PRINT AT 4 1 0; M SALES*HISTORY<inclusi ve> "
PRINT AT 7, 6; “FROM*YEAR"
PRINT AT lO* 6; "TO***YEAR“
PRINT AT 7, 17! FLASH l; INVERSE 15 " > "5
FLASH O! INK 25 INVERSE 15
INPUT S* t LET yl - INT < VAL S*> £ IF
y1 < 1900 DR LEN ( STR* yl> > 4 THEN
GO TO 1070
PRINT AT 7, 17! “2'; yl
PRINT AT 10, 175 FLASH 1; INVERSE l; " > "5
FLASH 0 5 INK 2; INVERSE 15 *****"
INPUT S* * LET y2 = INT ( VAL 5*> s
IF y2 < 1900 OR LEN < STR* y2> > 4 OR
y 2 < yl OR y2 > yi+17 THEN GO TO 1100
PRINT AT 10, 171 "^"5 y2
LET NY - y2-yl+l
DIM Y*( NY, 4) ; REM year
DIM Ht< NY * 4, 4> i REM sales*history
DIM A*<NY, 7> i REM annual *avr*sales
DIM ft*(NY, 4, 6) - REM ratios
DIM D*(4„ 6) = REM seasonal *index
DIM Qt4) - REM sum*cH^quarter*ratios
DIM C<NY> i REM draw A oirve*d«
DIM C (NY) i REM draw*curve A df?
DIM C (NY ) i REM dr aw *cur ve *dx
FOR I ^ yl TO y2 £ LET Y*(I-yl+I> = 5TR* I £
NEXT I
RETURN
REM
REM input*sales*history
CLS = PRINT AT O, 105 INVERSE l! "SALES*HXSTORY"
PRINT AT 1, 26; INVERSE 1; “AVR>"; AT 2, Oi
INVERSE l; "YEAR"! AT 2, 5; INVERSE 15 “QTR1"
AT 2, 10; "QTR2 M ; AT 2, 155 INVERSE l; i, QTR3 , ‘
AT 2* 205 INVERSE l; "QTR4"! AT 2, 26;
INVERSE l 5 “SALES"
IF hm = I THEN GO TO 2500
FOR I = 1 TO NY
LET Ln = 1+3-1 * PRINT AT Ln, OJ Y*II>
LET hp = 4 £ LET ts - 0
FOR J = 1 TO 4
PRINT AT Ln r hp; FLASH ll " > "I INVERSE 1;
FLASH 0; INK 25 "*_'*
INPUT S* i IF VAL S* < O THEN GO TO 2100
LET nl - INT ( VAL S*+-5) s LET ts = ts+nl £
LET S* = 5TR* nl
LET Z* = "****" £ LET Zf C5- LEN S* TO ) = 5*
PRINT AT Ln f hp; "Z*
LET H*(I, J> = 1% £ LET hp = hp+5
NEXT J
126
LET nd
2
2160 LET Si - STRi (ts/4> - LET ns = 4 i
2170 GO SUP 7000
2190 PRINT AT Ln, hp+l; Si
2190 LET A*(I) - Si
2200 NEXT I
2210 LET h(n = 1 ? GO TO 2550
2500 REM
2510 REM display
2520 FOR I = 1 TO NY
2530 PRINT AT 1+3-1, 0 5 Yi d > ; Hi ( 1, 1>; 5
Hid, 2>; i Hit I, 3); H*<I, 4);
11 * " s Ai t n
2540 NEXT I
2550 INPUT "Copy ithi s*to*pri nter <y A or 11 ; ki
2560 IF k* = "y" OR ki - "Y ,r THEN COPY * GO TO 2550
2570 IF ki * ”N M OR EXT SHI Oki - "n" THEN RETURN
2560 IF k* = "E“ THEN CLEAR s STOP
2590 60 TO 2550
3000 REM
3010 REM caltzul ate^rat i os
3020 CLS i PRINT AT 0, 9i INVERSE U "COMPUTED^RATIOS
3030 PRINT AT 2, 0; INVERSE 1; "YEAR"; AT 2, 6; "0TR1
AT 2, 135 11 QTR2" 5 AT 2, 20; "QTR3" 5 AT 2, 27;
,[ QTR4"
3040 PRINT AT 21, Ol INVERSE li "INDEX"
3050 IF cm = 1 THEN GO TO 3500
3060 PRINT AT 1, li; FLASH 15 INK 3; "CALCULATING"
3070 FOR I = 1 TO 4 - LET Q(H =0 s NEXT I
30B0 FOR 3 = 1 TO NY
3090 LET n1 — VAL Aid)
3100 FOR J - L TO 4
3110 LET n2 = VAL Hid, J> t LET n3 = n2/nl
3120 LET Si = STRi n3 * LET ns = 1 * LET nd = 4
3130 GO SUB 7000
3140 LET Rit I, J) = Si i LET Q<J) = Q<J>+ VAL Si
3150 BEEP -03, 12
3160 NEXT 3
3170 NEXT 1
3180 FOR 1=1 TO 4
3190 LET nl = Qd)/NY
3200 LET Si = STRi nl s LET ns = 3 - LET nd = 4
3210 GO SUB 7000
3220 LET Did) = Si
3230 BEEP .05, 24
3240 NEXT I
3250 PRINT AT 1, 11; i INVERSE 1; INK 3J
"FINISHED"5 INVERSE Q; INK i;
3260 LET cm ~ 1
3270 NEXT I
3280 PRINT AT 1, 11; "*'‘3 INVERSE 15 INK 35
"FINISHED"; INVERSE 05 INK 15
3290 LET cm - 1
3500 REM
3510 REM redisp1ay atios/index
3520 FOR I ’ 1 TO NY
3530 PRINT AT 1+3-1, Oi Yi d > 5 "**'i Rid, 1); " l
Rid, 2); " *" ; Ri < 1, 3 > ; ; Rid, 4>
3540 NEXT I
3560 PRINT AT 21, 55 Did); Di<2); H /j Di(3);
127
3570
3500
3590
3600
3610
4000
4010
4020
4030
4040
4050
4060
4080
4090
4100
4110
4120
4130
4140
4150
4160
4170
4180
4190
4200
4210
4220
4230
4500
4510
4520
4530
4540
4550
4560
4570
4580
4590
4600
4610
4620
4630
4640
7000
7010
7030
7040
7050
7060
7070
■***'3 D*(4)
INPUT "Copy*thi s *to *pr i nter <y *or *n> *■; kt
IF k % « "y" OR k* * *■ Y" THEN CORY ± GO TO 3570
IF k% = “n" OR k* = "N" THEN RETURN
IF k * - "E" THEN CLEAR $ STOP
GO TO 3570
REM
REM plot^sales^graph
CLS ? PRINT AT O, lOl INVERSE 15 SALES ^GRAPH-
PRINT AT 2, OS INVERSE l; *'YEAR" ; AT t, 26i
INVERSE IS “AVE"S EXT SHI O AT 2, 26; INVERSE 1
'* SALES"
IF gin = 1 THEN BO TO 4500
LET gm = 1
PRINT AT 2, 12; INVERSE 1; INK 3;
FLASH i; "PLOTTING"
LET max = INT ( VAL At(1)1 * LET min = max
FOR I =2 TO NY
LET nl = INT ( VAL At<I)>
IF nl > max THEN LET max = nl
IF nl < min THEN LET min = nl
BEEP .05, 0
NEXT I
LET ran - max—min
LET rat = INT <ran/152+.5)
LET ox = 40
FOR 1=1 TO NY
LET nl = INT i VAL At<1>> * LET nx = INT
( (nl-min) / rat+ .5) +40
LET CCI> = nx-ox * LET ok = nx
BEEP .05, 24
NEXT I
PRINT AT 2, 12; " ****
REM
REM redisplay^sales^curve
FOR 1=1 TO NY
LET Ln - 1+3-1 * PRINT AT Ln, O; Y*<1); AT Ln, 25?
At Cl)
NEXT I
PLOT 40, 155 s DRAW 151, O * PLOT 40, 155 *
DRAW O, -155
PLOT 40+C < 1) , 147
FOR I = 2 TO NY
DRAW C(l>, -8
NEXT I
INPUT "Copy A to*printer A Cy^or A n> *'* i kt
IF kt = '*y" UR kt = "Y“ THEN COPY i GO TO 4600
IF kt = "n rt OR kt = "N" THEN RETURN
IF H = "E" THEN STOP
60 TO 4600
REM
REM number A tn mmi nq
LET X$ = "„„„****" i REM lOiSpaces
LET Wt = " 1000000*' * REM 6^decimal 1 aces
LET Tt = STRt l INT VAL S*>
IF ns > O THEN LET T* = HU TO ns-
LEN Tt) +Tt+ '*. " s
GO TO 7000
LET T* = "* O"
128
7080
7090
7100
7110
7120
7 T 30
8000
8010
0020
0030
8040
8050
8060
8070
LET n3 = VAL W* U TO nd+l> =
REM nd *is^number A o i ^decimal^places
LET US * STRS ( INT << VAL St- VAL TS)*n3+,5>)
IF VAL US < VAL WSU TO nd) THEN LET
US = WS(2 TO nd- LEN US+D+U*
IF ns = 0 THEN LET TS =
LET SS = TS+US
RETURN
REM
REM main*loop
LET hm — 0 s LET cm — hm ? LET gm = hm *
REM j, ni t *d i spl ay A inode
BO SUB 1000
GO SUB 2000
GO SUB 3000
BD SUB 4000
GO TO 8040
REM input*year ^range
REM input*saistory
REM caculatBS
REM plot*graph
129
Possessions Evaluation
Copyright (c) Beam software
DESCRIPTION
This is one of the three financial model programs in
this book. The model will assist individuals in
itemizing and evaluating their personal possessions. The
evaluation is useful for insurance coverage and claims
for fire or theft Losses. It could also be used for
capital expenditure items in a small business, such as
office or manufacturing equipment.
Each possession is evaluated on its original cost,
resale value, and replacement cost.
The resale value is calculated according to
straight-line depreciation, and the replacement cost is
based on the local inflation rate.
Replacement value could also be evaluated using an
accepted price appreciation rate in place of the local
inflation rate.
HOW TO RUN THE PROGRAM
The whole model is again screen driven. You have to
enter BASIC INFORMATION first before you can enter any
information about items that you own,
BASIC INFORMATION
NAME E 20 chars
CURRENT YEAR ; 4 chars, has to be at least
m2
LOCAL INFLATION : less than 100 percent
NUMBER OF ITEMS : less than 100
ITEM INFORMATION
DESCRIPTION
LOCATION
DATE ACQUIRED
LIFE
original cost
LO until
10 chars
4 chars before this year
within 100 years
numeric
PROGRAM STRUCTURE
The structure of the program is as follows:
130
INITIALISATION
INITIALISE STRING VARIABLES ( NAME AND YEAR )
INPUT BASIC INFORMATION
INITIALISE ARRAYS OF descript Ion
location
date acquired
life
INITIALISE ARRAYS
INPUT ITEM INFORMATION
SET UP ITEM SCREEN
INPUT ITEM DATA FIELDS
CALCULATES RESALE VALUE
CALCULATES REPLACEMENT COST
MAIN LOOP
PERFORM INPUT ITEM INFORMATION
UNTIL all items finished OR inkeyS -
LOAD HEADER SCREEN
DISPLAY FINAL HEADER INFORMATION
STOP
SPECIAL NOTES
You will notice that all values in this model are
displayed as integer only. This is justifiable as all
long term possessions need only to be valued to the
nearest dollar*
The author has decided to leave you the challenge of
further developing this program to make it capable of :
* redisplaying each item information sequence
* finding items in the same location and grouping
them together
131
POSSESSIONS EVALUATION
too
no
120
1000
1010
REM EVALUATE
REM possessions*evaluation^program
GO TO 9000
REM
REM Header^display^routxne
?n
1020
1030
REM
REM Display*scr
1040
CLS i
PRINT AT
PRINT
AT 2, i
1050
PRINT
AT
4 f 35
1060
PRINT
AT
6, 3;
1070
PRINT
AT
8, 31
1080
PRINT
AT
10, 35
1090
PRINT
AT
12, i*
1100
PRINT
AT
14, 3;
i 1 SO
PRINT
AT
15, 3 5
1 120
PRINT
AT
16, 23
1 130
PRINT
AT
17, 3;
1140
PRINT
AT
18, 23
1150
PRINT
AT
19, 3;
..
1160
PRINT
AT
21, 35
u 6; " POSSESS IONS ^EVALUATION"
a; «-—-—-—”
■NAME i*' 1
"CURRENT *YEAR s
■LOCAL^INFLATION - ^7."
"NUMBER ^OF * ITEMS i
■■TOTAL" i PRINT AT 13, 1 ? » —
"REPLACEMENT A VALUE* *'"
" DR IGINAL A ^ * * VALUE"
"DIFFERENCE"5 AT 17, 22; "
"pc * CHANGE" ; AT 19, 14;
"TOT ^CURRENT A VALUE * * 1 *'
1170
5000
5010
5020
RETURN
REM
REM Record *routi
REM Display*recor
ne
d ^screen
5030
FUR I
* 1
TO NI
5040
CLS i
PRINT AT t. 8 1 ** ITEM ^DESCRIFTIDN"
PRINT
AT 2, 8i “--—— -*
5050
PRINT
AT
4 t l; "DESCRIPTION *"
5060
PR I NT
AT
6, 13 "LOCATION * J '
5070
PRINT
AT
0, IS "DATE*ACQUIRED ±"; AT
8,
22;
"LIFE
*4,yrs“
5080
PRINT
AT
10, ii ■ORIGINAL*COST s’"
5090
PRINT
it
AT
13, 13 "CURRENT" s PRINT AT
14
9 lj
5100
PRINT
AT
16, 3; "RESALE*VALUE"i AT 16,
21 5 " ,ri
5110
PRINT
AT
18. 33 "REPLACEMENT *COST"
5120
PRINT
i*
AT
4, 143 INVERSE 15
II
5130
PRINT
AT
6, 111 INVERSE I; ********
"
5140
PRINT
AT
B, 163 INVERSE U " A ^ A ^ "
5150
PRINT
AT
B, 273 INVERSE 1 3
5160
PRINT
AT
10, 165 INVERSE 15 "******
'*
5170
REM lnputtern^rfata
5180
PRINT
AT
4, 0 5 FLASH 15 " > "
5190
INPUT
Did) s IF DtU f 1) = THEN
GO
TO 5410
5200
PRINT
AT
4, 14; INVERSE i; P* < I >
5210
PRINT
AT
4, 0 3 "* ,J - PRINT AT 6, 0;
FLASH 13 "
5220
INPUT
L*<IJ i IF Ltd) = *'*" THEN GO
TO
5410
5230
PRINT
AT
6, 11 ; LAJ mi o INVERSE
1 3
L*<I>
5240
PRINT
AT
6_, 03 "**■ ± PRINT AT 8, 05
FLASH 1 3 11
132
5250 INPUT T*<I) s IF VAL TS ( I, l TD 4) > VAL
C*U TO 4 > THEN GO TD 5250
5260 PRINT AT B, 16; INVERSE l; T*<I>
5270 PRINT AT 8, OS "* M = PRINT AT B, 21 5 FLASH 1;
" y M
52B0 INPUT Li IF L < 0 THEN GO TO 5280
5290 LET L = INF L 5 PRINT AT 8, 27; INVERSE 15 L
5300 PRINT AT 0, 21; ,f ^ PRINT AT 10, O; FLASH 1
tl V #1
5310 INPUT □ i IF O < 0 THEN GO TO 5310
5320 LET O = INT O s PRINT AT 10, 16; INVERSE 1; 0
5330 PRINT AT 10, O;
5340 REM ca]cul ate *res^le *valus
5350 LET yu = VAL CS- VAL Tf <I)
i LET yu =(yu < LHyu + Cyu >= L) *L
= LET rv = INT (lL-yu>*0/L>
5360 LET TC = TC+rv * PRINT AT 16* 23+7-
LEN ( STR* rv)S rv
5370 LET rc = INT <0*Cl+LI/100> yu>
‘ LET TR = TR+rc
i PRINT AT 18,23+7- LEN t STR* rc); rc
5380 LET TO = TO+O
5390 IF INKEV* *= " * THEN SO TO 5390
5400 NEXT I
5410 RETURN
6000 REM
6010 REM display^final^header
6020 PRINT AT 4, 9; INVERSE l; N*
6030 PRINT AT 6, 175 INVERSE IS C*
6040 PRINT AT B f 20; INVERSE l; INT <LI*100>/100
6050 PRINT AT 10, 20; INVERSE ii NI
6060 PRINT AT 14, 2^+Q- LEN ( SIR* TR> 5 TR
6070 PRINT AT 15, 24+8- LEN ( STR* T0>; TO
6000 LET di = ABS <TR-TO) - PRINT AT 17,
24+8- LEN < STR* di>; di
6090 IF TR < TO THEN PRINT AT 17, 21; s PRINT
AT 19, 12;
6100 PRINT AT 19, 145 INT ( (di / TO) » lOOOO) /100 i "*7.
6110 PRINT AT 21, 24+8- LEN { STR* TO; TC
6120 IF INKEY* <0 "*'* THEN GD TO 6120
6130 RETURN
8000 REM
8010 REM imtiali5e*data
8020 DIM Ct(4J J DIM N*<20) * LET N* = ”V* * LET
CY = 0 s LET LI = O t LET NI = 0 * LET
TR = O f LET TO = 0 * LET TC - O
8030 GO SUB 1000 ; REM display.header
8040 PRINT AT 4, 9; INVERSE l;
8050 PRINT AT 6, 17; INVERSE i; "„.***"
8060 PRINT AT 8, 20? INVERSE l; M AT 8, 23;
» ti
8070 PRINT At 10, 20; INVERSE i i M ^
8080 REM i nptit i el ds
8090 PRINT AT 4, 2; FLASH 1; '• > “
8100 INPUT N* - IF Ni ^ ,, * M THEN GO TD 8100
133
0110 PHINT AT 4, 9I INVERSE 1; (1 TO 20J
8120 PRINT AT 4, 2; s PRINT AT 6, 25 FLASH 1 ; ,r >
ii
Bl30 INPUT C* s IF VAL C* < 1982 THEN GO TO 8130
BI40 PRINT AT 6, 17; INVERSE 1; C*
B150 PRINT AT 6, 2; "*"
8160 PRINT AT 8, 2; FLASH li '* > "
81BO INPUT LI s IF LI > 100 OR LI < O THEN GO TO B180
8190 PRINT AT 8, 20; " EXT O EXT SHI 7" + 5TR* ( I NT
<Li*ioo>/ioo>+*' mi 7 mi mi o h
8210 PRINT AT 8, 2? " *« a PRINT AT 10, 2; FLASH H
■■ > ■■
8220 INPUT N1 s PRINT AT 10, 20;
" EXT O EXT S_t±J 7“ + STR* NI + M EXT 7 EXT SHI O"
8230 PRINT AT 10, 2;
8240 PRINT AT 12, 9; FLASH i; INK 3; "INITIALISING"
8250 DIM D$ fN1, 18>
8260 DIM L*(NI, 10)
8270 DIM TfcfNI, 4>
8280 DIM L<NI>
8290 DIM □ <NI )
8300 FOR I = I TD N t
8310 LET D*(I* = '**" s LET L* (I > = ^ ; LET
TS<I> »
8320 LET LCD = O * LET OCI) - O
8330 NEXT I
8340 PRINT AT 12, 9; INK 3S "FI N1SHED * A * *" * FOR
I = 1 TO 50 i NEXT I
8350 LET TR * O * LET TO ** TR * LET TC = TR
8360 RETURN
9000 REM
9010 REM main*loop
9020 GO SUB 8000 * REM input*header.data
9030 GO SUB 5000 * REM inputs item
9040 REM displayinal^header A inlo
9050 GO SUB IOOO
9060 GO SUB 6000
9070 PRINT AT 12, 9; FLASH 1? INK If "PROGRAM^ENDED"
9080 STOP
134
Chess
Copyright (c) Clifford Ramshaw and Beam Software
This program will allow you to challenge the
computer to a game of chess. But be warned the computer
is a terrible player arid it is very very slow.
Hovever this program does have some nice
graphics and for anyone who is a keen chess player
it should not be too hard to turn the computer into
a better player. Alternatively the program could he
changed to allow two human players to have a game.
The choice is yours.
This program is an excellent example of what
is possible on the SPECTRUM. Chess is generally
considered a game that is difficult for computers to
play. While this program in no way pretends to play
well it does show just what can be done in SPECTRUM
basic with a little effort.
When the program is run the computer will
set up the variables used, draw the board and pieces
and then ask you for a move* You are white Cat the top)
and your move is entered as letter from ‘a* to “h f
followed by a number from S 1‘ to '8 1 .
The computer does not check to see If your move
is a legal one so be careful, (unless you are unscrupul
and want to cheat).
How the program works
The following is a breakdown of the program
lines description
1
4
*
10 - 270
280 - 315
318 - 360
370
initial iiiatlon of the screen and
some variables that are used to
save space in the data statements
used to build the graphic chess
pieces
builds the chess pieces in the user
defined graphics set from the data
st at merits in lines 30 - 220
draws the empty board on the screen
dimensions the board array and the
arrays used to define the allowed
moves of the pieces, then fills the
board array
calls the subroutine to put the pieces
on the screen
300 - 500
builds the arrays used to define the
allowed moves of the pieces
600 - 630
main loop
1 get the players move
get the computers move
goto 1
000 - 900
inputs the players move
1000 - 1010
draw the piece ‘c 1 at board position
x,y
3000 - 3150
Input the players move and do it on
the screen
4000 - 4410
make the computers move
5000 - 5090
checks for checkmate of the computer
136
CHESS
1 FAPER 7 = BORDER 7 s CLS
2 LET p = 248 * LET t = 31 J LET a - 12B *
LET g - 13 5 LET h =* 160
3 LET b = 192 * LET d - 224 * LET e = 240 ±
LET f = 15
4 LET x ~ O * LET y = 1 - LET z - 3 * LET c - 7 *
LET i - 160
5
LET +4 =
111
DIM A4C1
, 1>
6
LET kx =
5
= !
LET
ky
-
8 i LET
10
FOR ii
U5R '0
a"
TO 1
USR
-t M +7
20
READ
n t
POKE
m i
n
t NEXT m
30
DATA
k*
x „
x ,
x ,
Xf
M,
Y t 7
40
DATA
x r
X ,
H ,
x*
X,
a, b
50
DATA
C*
c,
z ,
V*
Z*
f.
X , X
60
DATA
d,
d.
b.
a,
b.
d.
x , X
70
DATA
Yt
c,
C j
Yw
g.
f T c
80
DATA
a.
d.
dp
a.
176,
e t e, d
90
DATA
z f
Z)
z 9
Y 5
Fp
31 p x
100
DATA
b.
b.
bp
a*
dp
P> K
HO
DATA
4,
5,
2,
Vj
A
F„
Fp C
120
DATA
32*
h
> 64,
a.
b p
d, d, d
130
DATA
2 S
Y*
Yj
Yt
z*
c.
x
140
DATA
b,
a,
a.
a.
b.
d.
e, x
150
DATA
Y,
2 ,
c,
F,
14
* 9
, C, 2
160
DATA
a,
b.
h.
U2,
e.
d, d, b
170
DATA
x*
x .
x,
Xj
k?
5,
5, c
ieo
DATA
**
x *
X ,
X «
bp
bp d
190
DATA
x p
x *
X ,
Y*
Z*
F,
C. 2
200
DATA
x,
X ,
a.
b.
d *
p, 152
210
DATA
Y i
Y*
Y*
2 ,
F*
C,
f, X
220
DATA
a*
a,
a,
b i
d»
d *
e, x
230 DIM t*a f 2) * DIM bM7 t 2)
240 FOR x — 1 TO 7 s READ t4<x>, bH«) * NEXT x
250 DATA " ERA A Gflfl B% “ ERA C GR ft D%
*' tf RA Q GRft R% 11 fi RQ S GRft T '*
260 DATA " G8A M ERA N", " G.RB K gEB L",
■* FIR ft O GRft R", '■ GRft C ERA D"
270 DATA 11 ERA I ELLft J% ,f ERA K ERA L*' .
" G R ft E ERA F% " ERA S GRft H" ,
I# *1 U M
2BO LEtV ^2% LET p «* 4 * PRINT
290 PRINT i FOR x = O TO 7 ± FOR y = O TO 1 t
PRINT
300 FOR z * O TO 3 * PRINT PAPER p3 *'** H S PAPER H
” 11 i
310 NEXT 2 i PRINT * NEXT y ^ LET t = i ? LET i = p
t LET p = t ; NEXT x
315 FOR y ^ 1 TO B ! PRINT AT y+y, 05 y s NEXT y
320 DIN b < 8, 0J i FOR y = 1 TO B * FOR x = 1 TO B
330 LET z = (y = 8)*-b(x, U + (y = 2>*-i+(y = 7>
340 IF y = 1 THEN READ z
350 LET b«x* y > = z - NEXT x * NEXT y
137
360 DATA -4* -2, -3, -5. -6, -3, -2, -4
370 GD SUB 2000
3BO DIM d(6, 8, 2) ; DIM pt6)
390 FOR x - 1 TO 6 t LET p<x> = 2 * FOR y = 1 TO 0
400 LET d(x, y, 2) = ((y < 3) OR <y = 0>)+<(y > 31
AND fy < 7))*-l
410 LET d(x, y, 1) = t <y > 1> AND
<y < 5)>+(y > 5> 4-1
420
NEXT
y s IF x <> 2
THEN GO
TO
460
430
FOR y
^ 1 TO 4 s READ dIx,
Y?
1>>
LET
dU, y+4, 11
** —d (x ,
Yr
1)
LET
d(x s y+4, 2>
= —d Ik,
y t
2)
440 NEXT y
450 DATA —2, 1, -1, 2, 1, 2, 2, 1
460 IF k £ 1 THEN LET p(x> =8
470 IF X > 4 THEN LET p(x ) - 1
480 NEXT x
490 DIM c*<5) ; FOR m = 1 TO 5 J READ cllx) * NEXT x
500 DATA h p% "n H , "b% "r”, "q"
600 GO SUB 3000
610 PRINT AT 8, 22i FLASH If "THINKING";
620 GO SUB 4000
630 GO TO 600
800 LET A* <U = INKEY* * IF AH1) = “p" THEN
GO TO 900
805 IF <A*U) - OR <A*<1> < "a ,T > OR
IA*<1> > ‘‘h") THEN GO TO 800
810 PRINT A*(1>;
820 LET XI = CODE A*(1>-96
830 LET A*U> « INKEY* * IF (A*<1* = " " > OR
C A* ( |) < "A") OR (A*(i) > “B"> THEN GO TO 830
840 PRINT A* < L) ;
850 LET VI = CODE A*UJ-4B
860 RETURN
900 LET XI = 999 ? LET Y1 = O $ RETURN
1000 LET zl ^ INT < < ATTR <y+y f h+x>)/Q) i IF zl 8
THEN LET zl = zl-8
1O10 PRINT BRIGHT If PAPER zl; INK i? AT y+y s x+x?
# AT y+y+1„ x+x5 bvtc);
1020 RETURN
2000 FDR y - i TO 8 s FOR x = I TO 8
2010 LET z = b<K, y> i IF z ^ 0 THEN GO TD 2040
2020 LET i — 7 i IF z > O THEN LET i = O
2030 LET c = ABS z * GO SUB 1000
2040 NEXT x * NEXT y
2050 RETURN
3000 IF = "l" THEN PRINT AT 20, 22; "CHECKMATE" a
STOP
3010 PRINT AT 3, 22; “Your.move" i PRINT AT 4, 22;
"FROM*"; £ GD SUB 800 i IE Xl = 999 THEN
STOP
3020 LET X = Xt * LET Y = Y1
3030 PRINT AT 5, 24; "TO^" ; * GO SUB 800 i
LET XB = XI * LET YB ^ YI
3040 IF b<XB ? YBI >0 THEN
LET ptbfXB, YB)) - p < b(X B, YB>>~!
3050 LET b(XB, YB) a b<X, Y>
3060 LET btX, Y) =0 i LET i = 7
3070 IF biXB, YB) < -1 OR YB < 8 THEN GO TO 3120
3000 PRINT AT 6. 211 "Piece.’ 1 ;
3090 LET A*<1) = INKEY* *
3100 LET a = O * FOR z = 1 TO 5 - IF c*(z) = A*<I)
THEN LET a =* -2
3110 NEXT z t IF a - O THEN 60 TO 3090
3115 PRINT A*(1); * LET biXB, YB> ^ a
3120 LET c = 7 s GO SUB lOOO
3130 LET c - —b(XB* YB> ± LET x = XB * LET y " YB *
GO SUB 1QQ0
3140 PRINT AT 3, 22 i “ ** A * * * * " ; AT 4, 22;
_at 5, 24; "*.***/;
at 6, 21; i, ******* M ;
3150 RETURN
4000 LET xb = O s LET yb = xb * LET db = xb *
LET cL - 1 » LET bp = xb * LET x = 9
4010 LET ax = kx * LET ay = ky ± LET g* - M " -
GO SUB 5010 * LET g* ^ f*
4020 FDR y = 1 TO 8 * FOR x * 1 TO 8 ± LET tb = O J
LET C 2 = 1 * LET ty = O J LET tx = O *
LET d = O
4030 IF btx, y> < I THEN GO TO 4370
4040 LET p = b(x, y> * FOR i = 1 TO 0 *
LET dy = dip, i, 2) * LET dx = dip, i. U *
LET ax = kx t LET ay ^ ky i LET cl = 1 s
LET pa - O
4050 IF x+dx < 1 DR x+dx > 0 OR y+dy < 1 OR y+dy > 8
THEN GO TO 4300
4060 IF p > 2 AND p < 6 THEN GO TO 4210
4070 IF dy > -1 AND p = 1 THEN GO TO 4300
4080 IF y > 1 OR p > 1 THEN GO TO 4130
4090 LET p(5> * p<5>+l
4100 LET b <x f y> - 5
4120 GO TO 4300
4130 IF dx <> O AND bCx+dx, y+dy) > -1 THEN
GO TO 4300
4140 IF P - 6 THEN LET kx = x s LET ky = y *
LET ax = x+dx * LET ay = y+dy s 60 SUB 5000 *
IF f* = «1» THEN GO TO 4300
4150 IF dx = O AND b(x f y+dy) <> O THEN GO TO 4300
4160 LET po = S-p-bix+dx, y+dy)*3
4170 IF y <> 7 OR dx <> O OR bCx, 5) <> O OR p > 1
THEN GO TO 4300
4100 IF g* = "1" THEN GO SUB 5000 ^ IF f* = H " THEN
GO TO 4300
4190 IF g* ^ "1* OR RND > ,3 THEN LET cl = 2
4200 GO TO 4300
4210 LET xl = x * LET yl = y
4220 IF p - 3 AND INT (i/2)*2 < 1 THEN GO TO 4300
4230 IF p = 4 AND INT <i/2)»2 = J. THEN GO TO 4300
4240 IF xl+dx < I OR xl+dx > B OR yl+dy < 1 OR
yl+dy > 0 THEN LET cl - cl-1 * GO TO 4300
4250 IF b (xl+dx, yl+dy> > O THEN LET cl - cl-1 t
GO TO 4300
139
4260 LET po = B~p+ INT ( RND *3)-b<xl+dx, yl+dy>*3
4270 IF g* = "l" THEN GO SUB 5000 ± IF = ,,t ‘ THEN
LET po = po+50 i GO TO 4340
4280 IF b i x1+dx, yl+dy) <> O THEN GO TO 4300
4290 LET cl = cl + 1 ± LET x 1 = xl+dx * LET yl = yl+dy
i GO TO 4240
4300 IF po = O THEN GO TO 4340
4310 IF g* « "1" THEN GO SUB 5000 * IF ff a H ” THEN
LET po - pa+50 * GO TO 4340
4320 IF g* - 1,11 THEN GO SUB 5000 ± IF « = "l p THEN
LET po = O t GO TO 4340
4330 IF pa >= tb THEN LET ax = x+dx*cl -
LET ay = y+dy*cl * GO SUB 5000 * IF T* = "I"
THEN LET po = po-p#2
4340 IF po > tb THEN LET tb = po = LET tx = x :
LET ty - y * LET d = i * LET cz = cl
4350 NEXT i
4360 IF tb > bp OR ttb = bp AND i RND > .9 OR f
(ty < yb AND RND > -5))) THEN LET bp = tb ±
LET *b’ - tx ± LET yb = ty * LET cL - cz -
LET db = d
4370 NEXT x * NEXT y * LET p = btxb, yb) *
LET xl = xb+dtp, db, l>*cL *
LET yl = yb+d<p, db, 2)*cL * IF p = 6 THEN
LET k* - xl * LET ky = yl
4380 LET ax = kx * LET ay = ky t
LET b(xl T yl) = blxb, yb) * LET b<xb, yb> — O
i LET q = 1 - GO SUB 5010 * LET q = O
4-385 PRINT AT 8, 225 " - -******" ; AT 9, 22;
"My^mnve"! AT 10, 22; "FROM*"; CHRS (xb+95>;
"-■V; CHR* (yb+4B) ;
4386 PRINT AT 11, 24; "TOi N ; CHR* (xl+95>i ,, - M i
CHR* Cyi+40);
4390 LET i = O * LET c = 7 * LET x - xb s LET y = yb
t GO SUB lOOO
4400 LET c ” b tx1, yl) s LET x - xl - LET y = yl s
GO SUB lOOO
4410 RETURN
5000 *LET pc = b(x+dxic1, y+dytcl) ‘
LET blx+dxlcl, y+dy*cl> = b(x, y) ‘
LET btx, y> = O
5010 LET f* = "" s FOR r = 1 TO 6 ^ FOR j - 1 TO 8 *
LET dl = dtr, j, 1) * LET d2 ^ dCr, j, 2) *
LET L = 1
5020 IF ax+dl*L < l DR ax+dltL > 8 DR ay+d2*L < 1 OR
ay+d2*L > 8 THEN GO TO 5060
5030 IF r = 1 AND d2 < 1 AND q - O THEN GO TO 5060
5040 IF b<ax+dl*L, ay+d2*L> = -r THEN LET f* = "1" -
GO TO 5070
5050 IF r > 2 AND r < 6 AND b<ax+dl*L, ay+d2*L> - O
THEN LET L « L+l - GO TO 5020
5060 NEXT j 5 NEXT r
5070 IF x > 8 THEN GO TO 5090
5080 LET b(x, y) = bCx+dx*cl T y+dy*cl) s
LET b(x+dx*ci, y+dytcl) = pc
5090 RETURN
14o
Draughts
This program is a combination of basic and
machine language that plays a pretty fair game of
draughts *
The computer displays a graphic draughts
board, with your pieces (rod) at the bottom and its
pieces (black) at the top. You always move first and
your move is input as a "from value 0 that teLls the
computer which piece to move and a "to value' 1 which
tells the computer where to move it.
The squares are identified by a letter and
a number. The letters range from 'a* to f h’ and are
the columns of the board. The numbers go from '1 1 to '8'
and are the rows. For example an opening move could be
'FROM a6, TO b5 f (you type + a6 + and f b5 r ).
If you should happen to lose the game or wish
to quit just hit t 0 t as the first key when the computer
asks you for your move.
All your moves are checked for legality so
you can't cheat; but captures are not compulsory
(for you), and multiple jumps are not allowed.
The computer always captures if it can.
You make a king by getting a piece to the last
line. Kings move only one square and can only make
single captures but may move forwards or backwards
How It works:
The BASIC part of the program performs the
housekeeping functions, it sets up the board, accepts
and executes the player’s moves and graphically displays
all moves on the screen, A short machine language program
Is used to make the computer’s move. This was done to
allow the game to be played without having to wait
forever for the computer to make its move. For those
with an understanding of machine language, a listing
of this part of the program Is included,
*If you do not understand machine language
do not worry as this part of the program is typed
in as data statements at Lines 9000 - 9450. Just
be careful when typing them in.
As part of the machine language section the
computer has a representation of the board in memory
as a series of bytes. This is why PEEKs and POKEs
are used to make changes rather than using an array.
It is easier fur the machine language program to access
this board in memory than in an array.
141
The program
LINES
DESCRIPTION
10-20
These two lines set the top of
memory so that the machine language
program will be protected- The subroutine
at 9000 is then called to put the machine
language in memory.
30 - 79
This section sets the screen
attributes, and builds the board
represent ion in memory
SO - 160
Sets up the user defined graphics
for the pieces then displays the empty
board *
170 - 230
Puts the pieces on the screen in
initial configuration*
300 - 320
Main loop
1 get players move
get computers move
goto I
1000 - 1060
Draws a piece on the board at position
x 7 y with color c. The piece is determined
by p : 0 - blank
1 * normal man
2 - king
2000 - 2540
Inputs the player's move
It can be broken down as follows;
2000 -
2030 -
- 2020 dispLays message
- 2050 gets from value and checks it
2060 -
it is lega1
- 2110 gets to value and checks if
2120 -
it is a valid direction to move
- 2200 makes the player's move if it was
2500 -
a capture
- 2540 makes a normal move for the player
3000 - 3110
Calls the machine language program
for the computer's move and does that
move on the board
3 500
Displays the values of the
computer's move
3900 - 3904
The program jumps to here if the
computer has lost
4000 - 5010
Inputs an x,y value to be used in
the player’s move
If the player hits '0 r as the first key
142
the game ends and he is asked if he wishes
to play again
9000 - 9020 Reads the machine language program
from the data statements and stores
it into memory*
9100 - 9450 Comprises the data statements that
make up the machine language program*
143
DRAUGHTS
IO CLEAR 32019
20 GO SUB 9000
30 RESTORE 70
40 BORDER 7 s PAPER 7 s INK O *
50 FOR x = 32420 TO 32420+89
CLS
60
READ
a -
POKE x f a
5 NEXT x
70
DATA
255,
255, 255,
255,
255, 255, 255,
71
DATA
o.
< <
0, 1, 0,
1.
0,
1, 255
72
DATA
1,
0,
1, 0, U
0,
i.
O, 255
73
DATA
0,
1 ?
0, 1, 0,
Q,
1. 255
74
DATA
o.
0,
0, o, 0,
o,
0,
0, 255
75
DATA
o,
0,
Of 0, 0,
0,
Q*
Q. 255
76
DATA
0,
2, O t 2,
0,
2.
O, 255
77
DATA
o.
2,
0, 2, 0,
2v
0,
2, 255
7B
DATA
2,
o,
2, 0, 2,
0,
2,
0, 255
79
DATA
255,
255* 255,
255,
255* 255, 255
SO
FOR x
U5R "a" TO
63+
USR "a”
90
READ
a -
POKE x, a
± NEXT x
1O0
DATA
o.
7,
31, 63,
63,
127, 127, 127
101
DATA
o,
224, 249, 252,
252, 254, 254 v :
102
DATA
127,
127, 127,
63
, 63, 31, 7, 0
103
DATA
254,
254, 254,
252,
252, 248* 224
104
DATA
o.
31, 60,
56,
116, 98, 97
105
DATA
o.
224, 248, 60,
28,
46, 70, 134
106
DATA
V7,
98, 116, 56,
60,
31, 7, O
107
DATA
134,
70, 46, 28,
60,
248, 224, 0
255
255, 255
iio
115
120
130
PRINT
LET d
FOR y
FOR z
i PRINT
Vi
- 3 i LET L = 5
= 1 TO 8 : PRINT AT y+y, Oi
= 1 TO 2 s FOR >i = 1 TO 4
140 PRINT PAPER d; M **"J PAPER L; " „"i *
NEXT x i PRINT ± PRINT * NEXT
150 LET t = d * LET d = L - LET L = t
160 NEXT y
170
LET
P
=
1
180
FOR
X
2
TO 8 STEP
2
190
LET
c
0
i LET y =
1
s
GO
SOB
lOOO *
LET y - 3
# *
GO
SUB 1000
200
LET
c
-
2
* LET y =
7
t
GO
SUB
lOOO t
NEXT x
210
FOR
X
1
TO 7 STEP
2
220
LET
c
=
0
^ LET y =
2
i
GO
SUB
lOOO
230
LET
c
-
2
s LET y =*
6
i
GO
SUB
1000 s
LET y - 8
s GO SUB lOOO
300 GO SUB 2000
310 GO SUB 3000
320 GO TO 300
s NEXT x
1000
PAPER L ?
INK
c = PRINT AT
y+y, x+x;
1005
IF p s O
THEN
PRINT "
1010
IF p - i
THEN
PRINT « QB&
A
£HB
1020
IF p = 2
THEN
PRINT " ERA
E
ERA
F"i
1030
PRINT AT
y+Y+1
., x +x;
1035
IF p = 0
THEN
PRINT «
1040
IF p = 1
THEN
PRINT " ERA
C
ERA
D";
G Rfl G G Ft A H" 3
1050 IF p — 2 THEN PRINT
1060 RETURN
2000 PAPER 7 i INK 0 * PRINT AT 6, 22i "Your 4 move"
2010 BEEP - 5, 10 - PRINT AT 7 t 22l “FROM * -
2020 PRINT AT 0, 22; *' *TO A4 - ;
2030 LET L — 7 * GO SUB 4000 * LET fx ^ x *
LET fy = Y
2040 LET fp = 324l9+9*4y+4x s LET f - PEEK fp
2050 IF 4 <> 2 AND f <> 130 THEN GO TO 2010
2060 LET L = B - GO SUB 4000 * LET tx = x s
LET ty — y
2070 LET tp = 32419+9*ty+tx - LET t = PEEK tp
2080 LET d* = tx-4x = LET dy = ty—fy
2090 IF { ABS dx <> 1 AND ABS dx <> 2> OR
ABS dx <> ABS dy THEN 60 TO 2010
2100 IF (dy = 1 DR dy = 2> AND f = 2 THEN 60 TO 2010
2110 IF ABS dx = 1 THEN GO TO 2500
2120 IF t <> O THEN GO TO 2010
2130 LET jx - fx+dx/2 * LET jy = fy+dy/2
2140 LET jp = 32419+9*jy+jx - LET j = PEEK jp
2150 IF j <> 1 AND j <> 129 THEN GO TO 2010
2160 LET c = 2 : LET p - O * LET X = 4x £ LET y = 4y
s GO SUB lOOO * POKE 4p, O
2170 LET p-l± IF f = 130 OR ty = 1 THEN LET p = 2
2180 LET x = tx * LET y - ty t GO SUB LOOO *
POKE tp, 4 £ IF ty = 1 THEN POKE tp, 130
2190 LET p = O i LET x = jx £ LET y = jy ;
GO SUB lOOO * POKE jp, 0
2200 RETURN
2500 IF t <> O THEN GO TG 2010
2510 LET p - 0 s LET c = 2 s LET x - 4x *
LET y = fy s GO SUB lOOO - POKE fp, O
2520 LET p = 1 * IF 4 = 130 OR ty = 1 THEN LET p = 2
2530 LET x = tx - LET y = ty * 60 SUB lOOO *
POKE tp, f s IF y = 1 THEN POKE tp r 130
2540 RETURN
3000 LET mp - USR 32020
3002 PAPER 7 * INK O * PRINT AT ID, 221 “MY^ifiDve"
3003 F;RINT AT 11, 22; "FROM* ****";
3004 PRINT AT 12, 225 MO..
3005 FOR i = 1 TO 50 s NEXT i
3010 IF mp - O THEN 60 TO 3900
3020 LET fy = INT (mp/256) s LET ty = mp-256*fy
3030 LET 4x = INT (fy/16) * LET fy = 4y-l6*4x
3040 LET tx = INT tty/16) * LET ty = ty-l6*tx
3045 LET x - Fx i LET y = fy * LET z - li -
GO SUB 3500 - LET x = tx * LET y = ty *
LET z * 12 i 60 SOB 3500
3050 LET p = O ? LET x = fx * LET y = fy *
GO SUB lOOO
3060 LET tp = 32419+9*ty+tx * LET t = PEEK tp
3070 LET p = 1 * IF t = 129 THEN LET p = 2
3080 LET c = O s LET x ~ tx * LET y = ty £
GO SUB LOOO
3090 IF ABS Ctx —4x) 0 2 THEN RETURN
3100 LET x = fx+(tx-4x)/2 s LET y = Fy+(ty-4y)/2
145
3110
3500
3901
3902
3903
3904
4000
4010
4015
4020
4030
4040
4050
4060
GO SUB 1000 s RETURN
203 CHR* <*+64)3 CHR* (y+48> s
AT 20, o;
N 1 ihave ino+movei"
LET p = 0 s
PRINT AT z,
RETURN
3900 PRINT INK 03
*Y0U*WIN"
PRINT AT 21, O; "Another * game*?*"
IF INKEY* = MM THEN GO TO 3902
IF INKEY* * "y" THEN GO TO 50
STOP
PRINT AT L, 28 3 FLASH ii 3 CHR* 0 3
LET a* = INKEY*
IF a* = "O'* THEN SO TO 5000
IF a* < "a" OR a* > "h" THEN GO TO 4010
PRINT a* s LET x = CODE a*-96
PRINT AT L, 29t FLASH 13 “*'■5 CNR* 8;
LET a* ^ INKEY*
IF a* < "1" DR a* > "0" THEN GO TO 4050
4070 PRINT a* * LET y ^ CODE a*-48
4000 RETURN
5000 PRINT INK 0 3 AT 20, 0 3 ,T Bad* 1 uck *—* I *WON"
5010 GO TO 3901
9000 RESTORE 9100 * FOR x = 32020 TO 32301
9010 READ a * POKE n, a * NEXT x
9020 RETURN
9100 DATA 175, 33, 177, !25, 6, 10, 119, 35
9110 DATA 16, 252, 6, 35, 33, 174, 126, 126
9120 DATA 254, 1, 40, 16, 254, 129, 32, 24
DATA 17, 246, 255, 205, 187, 125, 17, 248
DATA 255, 205, 187, 125, 17, 8, O, 205
9130
9140
9150
DATA
1B7, 125
* 17, 10
* 0, 205,
187,
125
9160
DATA
35, 35,
16, 219,
58, 182,
125,
167
9170
DATA
40, 18,
42, 183,
125, 237
, 91,
185
9180
DATA
125, 229
, 126, 54, 0, 25,
54,
0
9190
DATA
25, 119,
24, 19,
58, 177,
125,
167
9200
DATA
40, 29,
42, 170,
125, 237
, 91,
180
9210
DATA
125, 126
, 54, 0,
229, 25,
119,
235
9220
DATA
225, 205
, 135, 125, 121,
230,
15,
9230
DATA
B, 1V2,
26, 246,
128, 18,
201,
t
9240
DATA
O, 0, 201, 235,
205, 146,
125,
79
9250 t>ATA 235, 205, 146, 125, 71, 201, 229, 213
9260 DATA 197, 17, 164, 126, 175, 237, 82, 61
9270 DATA 17, 9, O, 60, 237, 82, 48, 251
9280 DATA 71, 25, 125, 60, 7, 7, 7, 7
9290 DATA 128, 193, 209, 225, 201, O, 0, O
9300 DATA O, O, O s O, O, O, 0, 205
9310 DATA 19, 126, 254, 255, 200, 230, 127, 254
9320 DATA 1, 200, 254, 2, 40, 7©, 229, 25
9330 DATA 213, 17, 246, 255, 205, 13, 126, 40
9340 DATA 39, 17, 248, 255, 205, 13, 126, 40
9350 DATA 31, 17, 8, O p 205, 5, 126, 40
9360 DATA 23, 17, 10, 0, 205, 5, 126, 40
9370 DATA 15, 209, 225, 34, 178, 125, 237, 63
9380 DATA 100, 125, 62, i, 50, 177, 125, 201
9390 DATA 50, 177, 125, 167, 40, 235, 209, 225
9400 DATA 201, 205, 19, 126, 230, 127, 254. 2
9410 DATA 201, 205, 19, 126, 254, 130, 201, 229
146
9420
data
25,
126, 225,
201, 229 p
25, 205.
19
7430
DATA
126,
225, 254,
Q r 192,
62, 1, 50
7440
DATA
1B2,
125, 34,
1B3, 125,
237, 83,
195
9450
DATA
125,
201
4
147
ASSEMBLY LISTING FOR DRAUGHTS
00110 ;
7D14
00120
OfiS
32020
00130 3
0000
00140 BLANK
EQU
0 i
CODE FOR EMPTY SQUARE
FFFF
00150 NULL
EQU
"1 I
CODE FOR EDGE OF BOARD
0001
00160 BLACK
EQU
1 ;
CODE FOR A BLACK PIECE
0002
00170 WHITE
EQU
2 ;
CODE FOR A WHITE PIECE
0080
00180 KING
EQU
128 t
ADD THIS FOR A KING
00190 |
7EA4
00200 BOARD
EQU
32420 f
ADDRESS OF BOARD
00210 |
7D14
00220 START
EQU
%
7D14
AF
00230
XOR
A
7D15
21B17D
00240
LB
HL,MOVE i
CANCEL OLD MOVES FROM MEMORY
7D1S
060A
00250
LD
Bi 10
7D1A
77
00260 CLEAR
LD
(HL) t A
7D1B
23
00270
INC
HL
7D1C
10 FC
00280
DJNZ
CLEAR
00290 ;
7D1E
0623
00300
LD
B, 35 ;
B = COUNT OF POSITIONS TO CHECK
7D20
21AE7E
00310
LD
HL,BQARD+10 ; HL = POSITION ON BOARD
00320 ;
7D23
7E
00330 NEXT
LD
A,(HL) s
GET PIECE
7024
FE 01
00340
CP
BLACK ;
IS IT THE COMPUTERS MAN
7D26
2810
00350
JR
Z, MANFND ;
YES => NORMAL PIECE
7028
FEOi
i)0360
CP
BLACK+KING ; IS IT THE COMPUTERS KING
7D2A
2018
00370
JR
NZ,ENDSCH
s NO =*> TRY NEXT PIECE
702C
11F6FF
00380
LD
DE ,-10
l TEST BACKWARD JUMPS
7D2F
CDBB7D
00390
CALL
TEST
7D32
11F8FF
00400
LD
DE, -8
? FOR A KING
7D35
CDSB7D
00410
CALL
TEST
7D3S
110800
00420 MANFNO
LD
DE, B
; TEST FORWARD JUMPS FOR
7D3B
CDBB7D
00430
CALL
TEST
7D3E
110 A 00
00440
LD
DEL 10
a EITHER KINO OR NORMAL MAN
7D41
CDBB7D
00450
CALL
TEST
7D44
23
00460 ENDSCH
INC
HL a
NEXT PIECE (ONLY NEED TO CHECK
7D45
23
00470
INC
HL ;
EVERY SECOND POSITION)
7046
10DB
00480
DJNZ
NEXT
4
00490 ;
7D48
3AB67D
00500
LD
A, (CAPT)
a CHECK TO SEE IF A CART WAS
7D4B
A7
00510
AND
A
; WAS FOUND
7D4C
2 B 12
00520
JR
1 ,NORMOV
; NO ~> TRY A NORMAL MOVE
7D4E
2AB77D
00530
LD
HL,(CARTF!
3 WAS A CAPTURE SO MAKE
7D51
ED5BB97D
00540
LD
DE, (CAF'TD.:
i ; MOVE QN BOARD
7D55
E5
00550
PUSH
HL
7D56
7E
00560
LD
A,(HL)
! PIECE MOVING
7D57
3600
00570
LD
(HL) ,BLANK } NOW AN EMPTY SQUARE
7D59
1 ?
00580
ADD
HL, DE
7tm
3600
00590
LD
(ML),BLANK ; REMOVE PIECE JUMPED
7D5C
19
00600
ADD
HL f DE
7D5D
77
00610
LD
(HL),A
a PUT PIECE BACK IN NEW SQUARE
7D5E
1813
00620
JR
SOTMOV
; RETURN MOVE TO BASIC PROGRAM
7060
00630 NORMDO
EQU
%
7D60
3AB17D
00640
LD
A,(MOVE)
; CHECK FOR A MOVE FOUND
7063
A7
00650
AND
A
7D64
2610
00660
JR
Z,NOMOVE
; NO =: COMPUTER LOSES
7066
2AB27D
00670
LD
HL,(FROM)
i WAS A MOVE SO DO IT ON
7D69
ED5BB47D
00680
LD
DE,(DIR)
; BOARD
148
7B6D
7E
00690
LD
A, (HU
; SAVE PIECE
7D6E
3600
00700
LD
(HL),BLANK
; EMFTY SQUARE
7D70
E5
00710
PUSH
HL
7D7I
19
00720
ADD
HL, DE
7B72
77
00730
LD
(HL>,A
; PUT PIECE IN NEW SQUARE
7D73
EB
00740 GOTMOV
EX
DE* HL
; DE « NEW BOARD POSITION
7D74
El
00750
POF
HL
; RESTORE OLD BOARD POSITION
7B75
CD077D
00760
CALL
CONV
; CONVERT IT FOR BASIC PRC®RAM
7D78
79
00770
LD
A, C
7B79
E60F
00780
AND
L5
3 CHECK FOR PROMOTION
7D7B
FE08
00790
CP
8
; TO KING
7D7D
CO
00800
RET
NZ
3 NO = > RETURN TO BASIC
7D7E
1A
00910
LD
A,(DE)
; GET PIECE
7D7F
F6S0
00820
OR
KINO
; MAKE IT A KING
7mi
12
00830
LD
(DE),A
7DB2
C9
00840
RET
00050 }
7DB3
010000
00860 NQMOVE
LD
BC, 0
1 RETURN FAILURE TO
7B86
C9
00870
RET
? BASIC
00880
00090
THIS SUBROUTINE TAKES HL
AND DE AS BOARD
00900
POSITIONS AND CONVERTS THEN TO X,Y CO-ORDINATES
00910
FOR THE BASIC PROGRAM
00920
HL =>
B ( THIS WILL BE THE X.v VALUE OF THE
00930
"FROM"
POSITION FOR THE COMPUTERS
00940
MOVE )
0G9S0
DE =>
C t X.Y VALUE of THE >TG> POSITION )
00960
THE :
* VALUE IS IN THE TOP HALF OF THE REGISTER
00970
(B OR C) AND THE Y VALUE IS IN THE BOTTOM HALF
00900 :
l
7D87
00990 CONV
EGU
$
7D87
EB
01000
EX
DE, HL
7D88
CD727D
01010
CALL
CONVIT
3 CONVERT DE
7DBB
4F
01020
LD
C,A
3 INTO C
7D0C
EB
01030
EX
DE, HL
7B8D
CD927D
01040
CALL
CONVIT
i CONVERT HL
7D90
47
01050
LD
B, A
3 INTO B
7B91
C9
01060
RET
*
01070 3
01080 | CONVERT HL
INTO X,Y CO-ORDINATES AND RETURNS
01090
THE RESULT
IN A
01100
THE X
value
(THE COLUMN
DF THE PIECE UN THE BOARDi
OHIO
IS IN
IHE TOP HALF OF A
01120
THE Y
value
(THE ROW DF
THE PIECE ON THE BOARD)
01130
IS IN
THE BOTTOM HALF OF
A
01140
7D92
E5
01150 i
CONVIT
PUSH
HL
7D93
D5
01160
PUSH
DE
3 SAVE REGISTERS
TD94
C5
01170
PUSH
BC
7D95
11A47E
01180
LD
DE,BOARD
; HL IS ADDRESS OF PIECE
7099
AF
01190
XOR
A
3 SO NEED TO SUBTRACT OUT
7D99
ED52
01200
SBC
HL, DE
; ADDRESS OF BOARD TO GET
7D9B
3D
01210
DEC
A
3 OFFSET INTO BOARD
7D9C
110900
01220
LD
DE, 9
3 LENGTH OF EACH ROW
7D9F
01230 CNVL
EGJU
f
7D9F
3C
01240
INC
A
; INCREMENT ROW NUMBER
7 DAO
ED52
01250
SBC
HL, DE
; DECREMENT OFFSET
7DA2
30FB
01260
JR
NC, CNVL
; IF MORE ROWS CONTINUE
7DA4
47
01270
LD
B,A i B - ROW NUMBER (Y)
7DA5
19
01200
ADD
HL,.0E i GET BAD, COLUMN NUMBER
7DA6
7D
012#
LD
A,L i A = COLUMN NUMBER (X)
7DA7
3C
01300
INC
A ; FIRST COL IS NUMBER 1
7DAS
07
01310
RLCA
7DA9
07
01320
RLCA
| BUT IN TOP HALF OF REGISTER
7BAA
07
01330
RLCA
7DAB
07
01340
RLCA
7BAC
SO
01350
ADD
A ? B | ADD IN Y
7DAD
Ci
01360
POP
BC
7 DAE
D1
01370
POP
DE T RESTORE REGISTERS
7BAF
El
01380
POP
HL
7DB0
C9
01390
RET
01400
5
01410
; DATA
AREA FOR
NORMAL MOVES
01420
?
;dbi
00
01430
MOVE
DB
0 ; FLAG TO INDICATE IF A MOVE WAS FOUND
7DR2
0000
01440
FROM
DW
0 ; BOARD ADDRESS OF PIECE TD MOVE
7DB4
0000
01450
DIR
DW
0 i DIRECTION to move it
01460
5
01470
; DATA
AREA FOR
CAPTURES
01480
■
7DB6
00
01490
CAPT
DB
0 ; FLAG
7DB7
0000
01300
CAPTF
DW
0 ; BOARD ADDRESS OF PIECE
7DB9
0000
01510
CAFTC
DW
0 | DIRECTION TO MOVE
01520
01530
01540
01550
01560
01570
01580
0159 $
01600
01610
01620
01630
01640
01650
01660
TEST TYPE OF MOVE POSSIBLE FOR PE ICE AT POS <HL>
MOVING TO POS (HLK(DE)
IF A LEGAL MOVE IS POSSIBLE IT IS STORED
IN THE BATA AREA FOR A NORMAL MOVE
IF A PIECE CAN CAPTURE ITS MOVE IS PUT
IN THE CAPTURE DATA AREA
LEGAL NORMAL MOVES WHICH WOULD RESULT
IN POSSIBLE TRAPS (IMMEDIATE CAPTURE)
ARE SAVED ONLY IF WQ OTHER MOVE HAS
01670 ;
BEEN
FOUND TD DATE
01680 }
7DBB
01690 TEST
EDU
*
70BB CD137E
01700
CALL
BRDPCE
7DBE FEFF
01710
CP
NULL ;
CHECK FOR MOVE OFF BOARD
7dco ce
01720
RET
2 i
m MOVE IF so
7DC1 E67F
01730
AND
07 FH
7DC3 FE01
01740
CP
BLACK ;
OR ONTO OWN MAN
7DC5 C8
01750
RET
Z
7BC6 FE02
01760
CP
WHITE i
CHECK FOR A CAPTURE
7DCS 2S4E
01770
JF
Z* EVALCAP7
1 YOE -> CHECK IF VALID
01780 ;
01790 ; EVALUATE A
NORMAL MOVE
01800 s
7DCA E5
01810
PUSH
HL
7DCB 19
01820
ADD
HL S DE
7UCC D5
01830
PUSH
DE
7DCD 11F6FF
01840
LD
DE, -10 ;
CHECK FOR TRAPS
150
7DD0 CD0D7E
01850
CALL
GETPCE
; IB THERE A t ING BEHIND FIECE
/DD3 2827
01860
Oh'
Z * TRAP
j YES A TRAP
7DD5 1IFSFF
01070
LD
DE, -S
7DD8 CD0D7E
01880
CALL
GETPCE
7DDB 281F
OX890
JR
1 ,TRAP
7DUD 110800
01900
LD
DE f 8
: IS IHERE ANY PIECE IN FRONT
7DE0 CD057E
01910
CALL
GETPC1
; OF COMPUTERS MAIN
7DE3 2817
01920
JR
Z,rPAP
: YES => A TRAP
7DE5 11 WOO
01930
LD
DE, 10
7DE8 CDQ57E
01940
call
GETPCI
7DEB 2B0F
01950
JR
Z,T RAP
01960 ;
7DED D1
01970 SAV1T
POP
DE 1
m TRAP SO SAVE 1WE
7DEE El
01980
FOP
HL
7DEF 22B27D
01990
LD
iFROM) t HL
7DF2 ED53B47D
02000
LD
(DIR),PE
m &o j
02010
LD
H, 1
7DF8 32B17D
02020
LD
iMOvOpA ;
SET FLAG TO SAY MOVE FOUND
7DFE C9
02030
RETT
02040 ;
7DFC
02050 TRAP
EOU
%
7DFC 3AB17B
02060
LD
A,(MOVE) j
WAS A TRAP SO SEE IF ANY
7DFF A 7
02070
AND
A 3
OTHER MOVES
7E00 2BEB
02000
JR
z,saoit *
NO => SAVE THIS ONE
7E02 D1
02090
POP
DE !
ELES IGNORE IT
7E03 El
02100
POP
HL
7E04 09
02110
RET
02120 ;
7E05
02130 GETFC1
EQU
%
; CHECK IF PIECE AT 1HL)+(DE?
7E05 CD137E
02140
CALL
ERDPCE
7E08 E67F
02150
AND
07FH
5 IS ANY WHITE PIECE
7E0A FE02
02160
CP
WHITE
7E0C C9
02170
RET
•
02180 ;
7E0D
02190 GETPCE
EQU
%
? CHECK IF PIECE AT (HLJMDEJ
7E0D CB137E
02200
CALL
BRDPCE
7E10 FE82
02210
CF
WHITENING
S IS A WHITE KINS
7E12 C9
02220
RET
0
02230 s
7E13 E5
02240 BRDFCE
PUSH
HL
; RETURN PIECE AT (HL>+(DE)
7EI4 19
02250
ADD
HL, DE
7E15 7E
02260
LD
A.(HL)
7E16 El
02270
POP
HL
7E17 C9
02200
RET
02290 ;
?E18
02300 EVALCAPT EOU
$
; CHECK FOR A VALID CAPTURE
7E18 E5
02310
PUSH
HL
7EI9 19
02320
ADD
HL, DE
7E1A CD137E
02330
CALL
BRDPCE
t GET PIECE ON DTHERSIDE
7EID El
02340
POP
HL
t Of PIECE TO CAPTURE
7E1E FEOO
02350
CP
BLANK
? IS IT EMPTY
7E20 CO
02360
RET
NZ
( NO = NO CAPTURE
7E21 3E01
02370
LD
A,i
; YES => SAVE CAPTURE
7E23 32B67D
02380
LD
(CAFT), A
7E26 22B77D
02390
LD
(CAPTF> t HL
7E29 ED53B97D
02400
LD
(CAPTD1,DE
7E2D C9
02410
RET
02420 ;
151
Adventure
An adventure is a program that allows you to
enter and explore strange new worlds, find treasures
and battle fierce monsters- As an adventurer you must
solve the riddles and problems of the world you will
enter if you are ever to leave alive,.
This program allows you to have an adventure
on your SPECTRUM. The computer will describe the locations
you will visit and the things you will see. Also it
will prompt you to tell it want you want to do* The
commands you may use consist of one or two words* You
must always supply a verb (i*e the action you wish to do)
and often you will need a noun (i.e the object you wish
to perform the action on)*
Some examples are E
■north' - move north and have a look around
'take axe 1 - if there is an axe where you
are this will tell the computer
to try and pick it up for you
In a few cases you will be asked for more
information after you have given the computer a command.
For example if you say
'kill dragon' the computer will ask you what
you wish to kill it with. In this case just enter the
name o£ the weapon you wish to use or nothing (just hit
enter) if you want to use your bare hands*
As well as giving you an adventure to play this
program also allows you to easily create your own worlds
for yourself or a friend to adventure in.
How to play
The computer will display a description of the
location that you are in and it will describe any objects
that you can see* It will then ask you what you want to do.
You must then answer with a command as described above.
The computer will try to perform your command and if alt
goes well it wilt go back and do this all over again*
If hot&ver your command does not work - perhaps because
of a spelling mistake - or if you are not able to do
the command yet the computer will print an appropriate
message* go back and try again*
Some of the comttands you can use are
north, south, east, west,, up and down
These allow you to move around,
inventory - lists everything you are carrying
take — picks up objects
drop - drops objects
etc
If an object description has an adjective in it
- e,g 'mean troll', then you cannot say 'kill troll'* You
must use f kill mean troll' or just 'kill mean'*
Note most words may be abbreviated to one or two
lettersj provided this does not cause any ambiguity
between words* if an abbreviation would match more than
152
one word the computer uses the first one it finds
When playing an adventure it is usually a good
idea to draw a map of the world you are exploring. Since
many adventures contain mazes it is almost impossible to
find your way around unless you have a good map showing
you which way to go.
How the program works
This program consists of two distinct parts
Firstly there is the data base that is in effect the
game. It contains all the descriptions! objects and
actions that make up the game. Secondly there is the
program needed to allow the player to interact
with the data base. This consists of the initialization
tor the game, getting the users input and performing
the desired action.
The data base
The fundamental parts of this adventure are
the locations that make up the world* a map describing
how these locations are connected, the objects that
exist in this world and ail of the actions that the
player may perform. The way that each of these is built
up wilt now be described in more detail
Locations
For each location we need a description to give
the player to tell him where he is and a list of the
locations he can get to from where he is. As welt as these
it is often useful to have some sort of condition that
can be applied upon entering a location* These can be
anything from, making sure the player has a source of light
before allowing him lo enter, to performing some action
when he enters (such as making a monster attack him if
he is not carrying a particular object)*
aln this program each location has a unique number
that the computer uses to access that location. The numbers
start at 1 and increase in increments of 1 up to the last
location. For example this adventure has 30 locations.
The locations exist in the program in data
statements in the format
Line number DATA ,f st ring" ,N t S,E, W, If ,D, condition
The line number is the location number plus some
constant (9000 in this game).
The "string" is the description of the location.
The values N,S,E,W ( U,D are the locations that
the player will end up in if he tries to go in the
appropiate direction (north,southup,down). A value of
0 means there is nowhere to go in that direction.
The condition Is the number of the condition
to be performed upon entry to THIS location.
Conditions consist of short pieces of program
153
located at the condition number plus a constant (71Q0
in this program)
Objects
The Information we need For each object consists
of its description* where it is, what type of object it
is (i*e a treasure or a monster etc), how strong it is
and to allow greater flexibility a condition to he
performed if the player tries to pick up this object.
These conditions may be one that always fails to stop
people from taking things like tables, or one CO kill
the player if he tries to take a forbidden object
The computer knows about each object by its
number just like locations.
The format of the data For objects is slightly
different than that of locations. Each object has two
lines in the program describing it
The first is:
line number DATA "string"
where
lino number = object number + a constant (8000 in
this adventure)
and "string" is the description of the object
The second is :
line number DATA type,strength,condition
where
line number - object number + a constant (8500)
the type is 0 for an ordinary object
)0 for a treasure and this value is
the score for this treasure
(0 for a monster
strength this is used in two ways
for a weapon it is the value added
to the player strength if he uses it
in a fight
and for a monster it is its strength
that is matched against the player
4 in battle
condition is the condition to be done if
the player tries to take this object
Lastly we need the location for each object and
this is stored in an array. The initial locations for each
object (as well as the number of objects) are stored in a
DATA statment (at line SG0Q in this program) and the
location array is built from this*
The values used for these locations are
—1 - is used for objects that you cannot
see or use, such as dead animals
or treasures that have been returned
to the first location,
0 - is for objects being carried by the player
) 0 - all other objects and this value is
the location number of the object
154
The list of verbs that the player may use is
plated in data statements (starting at 7001 in this program)
Whenever a player types in a verb this list is searched
to find a match. Each verb also has a number which
the program uses to find the subroutine that performs
the action of the verb* The verb number is equal to
its position in the list (i.e the first verb is number 1)
and the subroutine to perform the verb is found at
a constant + 20 * the verb number (the constant is 1480
in this program so the first subroutine is at 1500 and
the others every 20 lines after that).
The following is a breakdown of the program
LINES FUNCTION
5 - 40 initialization
fixed value variables, screen parameters
and variables peculiar to this particular
adventure are set up here
50 - 110 control loop for the program
it consists of
1 print location description
print any visible objects
2 get the users input command
perform the action the player wants
if the action failed goto 2
goto 1
900 - 940 initialization of the variables
peculiar to this adventure
that is it sets up the number
of actions and objects, builds
the object location array and
defines some strings which are
common to a number of locations
4 to save memory space*
It also sets up some variables
that are used as conditions for
the game such as a door being
locked or unlocked etc
fOOp - 1100 inputs the players command
upper case is converted to lower
case and the first two words
of what the player typed are put
in the variables a$ and n$ Ca word
is any sequence of characters ending
in a space).
The verb list is then searched for
a$ and if it is found this subroutine
returns the verb number to the main
program, otherwise the player is
prompted to try again
155
1200 - 1260
1300 - 1311
1500 - 1802
1987
1988
1999
2000 - 2050
7000 - 7004
7100 - 7160
4
8000 - 8525
9001 - 9030
9980 - 9981
9990 - 9992
This subroutine searches a given list
for a given word. It is used to search
the verbs tor an action and the object
descriptions for an object
searches the object descriptions for
the variable n$ (the second word typed
in by the player)
If it is found it returns the description
found in the list, the object nmnber
and a flag to indicate that the search was
successful, otherwise the flag Is set
to indicate failure
This set of subroutines is used to perform
the actions required by each verb
This line is jumped to if some action
fails. It prints the message ’'You can’t"
and sets the flag to indicate failure
This line Is jumped to if an action
fails and the above message should not
be printed* it just sets the flag
This line is jumped to if an action
succeeds, it sets the flag to indicate
success
Lists all the objects whose location
Is equal to the variable 'l 1 . If none
are found it prints "nothing"*
This area contains the verb list
line 7000 contains the number of verbs
These are the conditions that are done
for taking objects or entering locations
Note condition 0 always succeeds so if
an object or location does not need a
condition it is given this one
this is the data for the objects
this is the data for the locations
These lines are jumped to at the end
of the game If the player has found
all the treasures successfully
This section is used at the end of the game
(either after the player has been killed
or if he finished the game) it prints the
score and asks if the game is to be
replayed
156
Haw to create your own adventure
Firstly you need a world to explore. This involves
building into the data base the descriptions of all the
locations to be visited along with the connections between
them. Along with this you will need to decide what if any
conditions will be applied to entering the locations.
As an example let us build a world with two
locations. These will be
A hall stretching as far as the eye can see.
and A small cavern.
The hall is north of the cavern and going south
from the hall ends up in the cavern. No other directions
are allowed. As a condition there will be a door between
the two locations that will be locked. The player can only
pass between the two if the door has been unlocked.
So we have
9001 DATA "in a hall stretching as far as the eye
can see",0,2,0,0,0,0,0
9002 DATA "in a small cavern",1,G,0,0,0,0,1
Note doors are only one way so that entering the hall has
no condition while entering the cavern requires that the
the door be unlocked.
Since the hall is the first location this will
be where the player starts and treasures must be put.
Now we need some objects. We already need a locked
door and an unlocked door (at the start the locked door
will exist between the locations but when the door is
unlocked we will put the locked door in location -I to
get rid of it and replace it with the unlocked one).
Obviously we also need a key to unlock the door. For
a treasure let us have an emerald in the cavern.
As well there will be a sword in the hall and a snake
guarding the emerald.
So we have
object
type,
strength,
condition
location
Locked door
O
0
fail
1
unlocked door
0
0
fail
key
0
0
0
1
sword
0
10
0
1
snake
-1
100
f ai 1
2
emerald
30
0
2
2
This means that the player cannot take either
door or the snake, and the emerald can only be taken
if condition 2 is met. We will write condition as a test
for the snake being alive.
The sword has a strength of 10 and the snake 100
so if the player starts with a strength of 100 the fight
between them should be fairly matched with a slight
advantage to the player.
The emerald has a score of 30, the snake Is
a monster and all else are just objects.
In the program this would be
157
8000
DATA
6,1,-1,1,1,2,2
8001
DATA
’’locked door"
8002
DATA
"unlocked door 1
8003
DATA
"key"
8004
DATA
"sword"
8005
DATA
"snake"
8006
DATA
"emerald"
8501
DATA
0,0,ta-cs
8502
DATA
0,0,fa-cs
8503
DATA
0,0,0
8504
DATA
0,10,0
8505
DATA
-1,100,Fa-cs
8506
DATA
30,0,2
(Fa is the address of
failure routine and cs
is the address of the
conditions so fa-cs is
a condition that fails)
Now we need the actions to perform. The movements
and their subroutines as well as ’inventory 1 * 1 take 1 ,
’drop 1 and ’kill’ are fairly standard and will probably
be used in all your adventures so look at the program for
these. The other action we will have will be f unlock’ fur
the door, so the verb list will be
7000 11 (this is the number of actions)
7001 DATA "north","south"/"east"/’west”
7002 DATA "up” *’’down" * "take” *’’drop"’
7003 DATA ’’ki 11" * "inventory ”, ”un lock"
The only routine we need write is for unlock.
This needs to check if the player is in the hall and
is carrying the key and the door is still locked. We
now need a variable to indicate if the door is locked
or not say ’lu T (remember this must be initialised at
the start or the door may be unlocked when we thought
it was locked).
Unlocking, then will consist of
1700 IF lu - 3 OH 1 () 1 OR o(3) () 0
THEN CO TO fa (check conditions)
1701 LET o(l) - -1 (got rid of locked door)
1702 LET o(2) =1 (replace it with other one)
1703 LET lu = 1
1704 GO TO tr
(set variable)
(success)
Now we need the conditions, we only have two
and they are
1 is door unlocked
and 2 is the snake dead
In the program these will be
7101 GO TO fa+lu (if iu^Q this will go to fa
and fail, if lu=l this will
goto tr and succeed)
7102 GO TO fa+(o(5)=-i)
The second of these may need some explanation
What it means is IF o{5) — 1 THEN GO TO tr
else IF o{5)(M THEN GO TO Fa
It works because the statement (o(5)=-l)
will be equal to 1 if of5)^-1 and it will equal
0 if o(5) () **1,
So now we have an adventure even though it
is pretty small. Good luck writing your own.
158
Adventure
5 LET tr = 1999 = LET la - 1998 * LET Ls ^ 9000 s
LET as = 8000 * LET oz = 8500 s LET vs ^ 7000
s LET cs = 7100 * LET sc = O
6 LET vr = 14BO i LET z = 0 * LET ct = 1997 ;
LET dr - 1601 < LET cx = 6 ? LET st = .100
10 BORDER 5 ± PAPER 7 ; INK 0 * CLS
30 LET L = 1
40 80 SUB 900
50 POKE 23692, 255 ± RESTORE L+Ls ; READ mi *
PRINT "YoUiSre* 1 '; mi * LET qi = M YQu*see 1 ' ;
GD SUB 2000
60 BEEP .2, 12 t PRINT
70 GD SUB 1000
80 PRINT vi; »;
90 GO SUB vr+vn»2Q
100 IF 1 = O THEN GO TO 60
110 PRINT - GO TO 50
900 RESTORE os t READ dc - DIM o(oc)
910 FOR i = 1 TO oc ± READ all) * NEXT 1
920 RESTORE vs s READ vc
930 LET be = O = LET Lu * Q * LET gu = O *
LET et = "tn A an ^endless^desert w ?
LET pi - M i n *a ^passage "
940 RETURN
1000 INPUT "Tell idieiHhatitOidOi'T si *
IF LEN si = 0 THEN GO TO IOOO
1O10 LET ai = H,< ; LET ni = 11 "
1020 LET K - O * FOR l — 1 TO LEN si
1030 LET ii = siU TO D
1040 IF if >— "A" AND ii <= "2" THEN
LET jt = CHRi <32+ CODE ii)
1050 IF ii = 11 * H AND x = 1 THEN LET i = LEN si *
GO TO 1080
1051 IF if = THEN LET ft = 1 * SO TO 1080
1060 IF k = O THEN LET ai = ai + ii
1070 IF k = 1 THEN LET ni = ni+a i
1080 NEXT a * LET wf = ai - LET c - vc s LET d = vs+1
4 s GO SUB 1200
1090 IF vn = O THEN FBINT
" LI1L I idon't^understand TRU ai * GO TO 1000
1100 LET vf = yi = RETURN
1200 LET vn = O
1210 RESTORE d
1220 FDR i = 1 TO c s READ mi t LET x = LEN mi ±
IF x > LEN wi THEN LET * = LEN wi
1240 IF wi( TO x) = mi( TO THEN LET vn -is
LET yi - mi f LET i = c
1260 NEXT i * RETURN
1300 IF ni = THEN GO TO 1-311
1301 LET mi = ni * LET c = oc * LET d = os+1 *
BO SUB 1200 s IF vn = 0 THEN GO TO 1311
1310 PRINT yi - GO TO tr
1311 PRINT 11 I NO I idon 7 1^understand mu * u j ni =
159
GO TO -Fa
1500 LET d = 1 ! BO TO dr
1520 LET d - 2 s GO TO dr
1540 LET d = 3 s SO TO dr
1560 LET d — 4 £ GO TO dr
1580 LET d = 5 * GO TO dr
1600 LET d = 6
1601 PRINT i RESTORE L+Ls ‘ READ m% $ FOR i = 1 TO d
- READ nL ± NEXT 1
1602 IF nL = O THEN PRINT "Ym A can^t A ga*that^y"
; GO TO fa
1603 RESTORE nL+Ls * READ m*, s, s* s, s, 5, s
1604 READ s
1605 GO SUB cs+s $ IF f = O THEN GO TO 1611
1610 IF ofl> =0 THEN LET L = nL * GO TO tr
1611 PRINT "Somethingestops A you“ * GO TO fa
1620 GO SUB 1300 * IF f = O THEN RETURN
1621 IF o(vn> <> L THEN PRINT ** 11'5*not ere" s
GD TO Fa
1622 RESTORE oz+vn - READ s * IF s < O THEN GO TO ct
1624 READ s
1625 READ s
1626 GO SUB cs+s * IF f = O THEN GO TO ct
1630 IF ex <> O THEN LET cx = cm-I # LET o<vn> = O *
RETURN
1631 PRINT *'You*are*carrying A too*much" 5 GO TO fa
1640 GO SUB 1300 s IF f = 0 THEN RETURN
1641 IF □ < vn) <> O THEN PRINT *■'You^don* t *have*i t*
s GO TO fa
1642 RESTORE oz+vn * READ s
1643 LET o(vn) = L * IF L - 1 AND s <> O THEN
LET sc = 5c+s * LET o(vn) = —I *
PRINT "The*" 5 y*; '^vanishes 11
1644 LET c* - cx + 1 * IF sc = 220 THEN GO TO 9980
1645 RETURN
1660 GO SUB 1300 * IF f = O THEN RETURN
1661 LET t* = y* * LET mn = vn t RESTORE oz+vn *
READ s, ms ± IF s >= O THEN GO TO ct
1662 LET s = O * BEEP <1, 20 4
* INPUT "ki11*with *what*7"? w* a IF w$ = ""
THEN GO TO 1670
1663 LET c — oc a LET d = os+I * GO SUB 1200 *
IF vn = 0 THEN GO TO 1662
1664 IF o(vn) <> O THEN GO TO 1662
1665 RESTORE oz+vn * READ s, s ? IF s - O THEN
GO TO 1662
1666 PRINT "*wLth*'‘i y*3
1670 PRINT s LET s = s+st - IF ms > s+ RND *20 THEN
GO TO 1679
1671 IF s > ms+ RND *15 THEN GO TO 1678
1672 PRINT "The 5 t*; '* ights *bac k.
^Vou^feel *«eaker"
1673 LET st = st“ RND *5 - GO TO tr
1670 PRINT "You 4 have 11 ed * the* 11 ; t* *
PRINT 11 The *. body *vani shes*in*a*doud *of
smoke" s LET o<mn> = —1 * GO TO tr
160
1679 PRINT "The^"5 1*; "*has 4 ki11ed*yous
GO TO 9990
1680 LET LI = L - LET L = 0 - LET qS = "You.are
^carrying" - GO SUB 2000 = LET L = Li *
GO TO tr
1700 PRINT sc ± GO TO tr
1720 GO SUB 1300 i IF f - O THEN RETURN
1721 IF vn <> 20 DR o(2> <> 0 THEN GO TO ct
1722 LET 0(141 = a WrO 5 LET a<vn> ^ -1 $
PRINT "Adii very a. key *fall5 *(ron *the
AAAAAceilir>g H ± RETURN
1740 IF L O 11 AND L <> 29 THEN GO TO ct
1741 IF L = 11 AND o<3) <> 0 THEN PRINT "You^ink
Atoxthe^bottom ake A 3nd
Adrown" * GO TO 9990
1742 IF L = 11 THEN LET L = 29 ? GO TO tr
1743 LET L = 11 s GO TO tr
1760 GO SUB 1300 * IF f — O THEN RETURN
1761 IF L = 1 AND of4> = 0 THEN LET o(22) - *1 i
LET o(23> = L * LET Lu = 1 * RETURN
1762 IF L = 13 AND oU4> =0 THEN LET o(24l = -1 ;
LET a(25> = L t LET gu = 1 ; RETURN
1763 GD TO ct
1780 IF o<16) <> O OR L < 3 OR L > 10 THEN GO TO ct
1791 PRINT "YouAfindA 11 ;
1782 IF L = 6 AND o<4> = -1 THEN LET o<4) = L ±
PRINT "something" = GO TO tr
1793 PRINT "nothing" s GO TO tr
1 BOO GO SUB 1300 * IF f = 0 THEN RETURN
1801 RESTORE oz+vn ? READ s* si, si
1802 IF s < 0 THEN GO TO ct
ISO3 GO SUB cs+sl 5 IF -f = 0 THEN GO TO ct
1804 PRINT "That *hits*the*spot" - LET o(vn) = -1 s
RETURN
1820 GO SUB 1300 s IF f = O THEN RETURN
1821 IF L <> 24 OR vn <> 7 THEN GO TO 1830
1922 PRINT "AidgeAapp^ars^across*the
* AAAAChasm" * LET oC15> = L * LETT be = 1
: GO TO tr
1930 F^INT "Nothing^happens" - GO TO ta
1840 IF L = 24 DR L = 26 THEN PRINT "Theal 1 .has
^broken A ypur*neck H s GO TO 9990
1841 GO TO 1830
1860 GO SUB 1300 - IF f — O THEN RETURN
1863 IF vn <> 19 THEN GO TO ct
1862 PRINT "That.was Adelicious" ^ LET o(19) = o(vn)
s LET o(vn) = “1 * RETURN
1997 PRINT "YouAcanH"
1998 LET f = O - RETURN
1999 LET f = lJ RETURN
2000 LET x = O ± PRINT q*
2010 RESTORE os+1 i FOR i - 1 TO oc * READ
2020 IF L <> o(i> THEN GO TO 2030
2021 LET x = 1 * PRINT “ ;
2022 LET zt = mtu TO 11 * IF zf * *'a N DR z$ = "*?”
OR z* = "i tt OR :$ = "o" OR z* * "u" THEN
161
2024
2030
2040
2050
7000
7001
7002
7003
7004
7100
7101
7102
7103
7104
7105
7106
7107
7150
7151
7160
GOOD
BOO 1
9002
0003
3004
8005
8006
8007
8008
8009
BO 10
8011
BO 12*
6013
6014
BO 15
BO 16
BO 17
0018
SO 19
8020
0021
8022
8023
8024
3025
0501
8502
PRINT "n J, 5
PRINT " ; m*
NEXT i
IF s ^ O THEN PRINT "*.nothing"
RETURN
DATA 19
DATA "north", "sooth", "east", "west", "up",
"down"
DATA "take”, "drop", "kill", "inventory",
“score"
DATA "cut % "swim", "unlock", "dig"
DATA "eat", "wave", "jump", "drink"
GO TO tr
GO TO fa+Lu
GO TO fa+qu
GO TO Fa+be
GO TO fa+(o<3> = 0)
GD TO fa+(o(3 1 > = -n
GO TO fa+(o(12> = -1>
GO TO fa+ <o CIQ) = -1)
IF o(18) <> 0 THEN GO TO tr
LET d( 10) = -1 * LET o(12) = -1 * PRINT "As^you
* enter ia^pirate * steal s ^ ^ ^ ^.your *fum
*and*run5^offaughing" * GO TO tr
PRINT "The *devi 1*ki11s*you" * GO TO 9990
DATA 25, 1, 12, 27, -1, 14, 17, 21, 25, 29, 12,
14, 17, 20, -1, -t, 11, 2, 2, -1, 19, 11, 1,
- 1 . 13 , -1
DATA "brass * 1 amp "
DATA “sword"
DATA "snorkel"
DATA "1arge*key"
DATA "persian*rug"
DATA "gold *.coin"
DAT A "si Iver*wand"
DATA "ruby"
DATA "diamond"
DATA "mean stroll"
DATA "green^dragon"
DATA "pirate"
DATA "devil"
DATA "i vory j.key "
DATA "crystal abridge"
DATA "shovel "
DATA "kitchen^tab1e"
DATA "bott 1 e*o-f 4 rum"
DATA "empty*bottle"
DATA "rope i ed ^between A the 1 oor ^and
*ceiIing M
DATA "small A Iake"
DATA “locked^door"
DATA "door"
DATA "padlocked^gate"
DATA "gate"
DATA z, z, z
DATA z, 20, 7
162
8503
DATA
Z T 2 , z
8504
DATA
z, z, z
B505
DATA
10, z, 5
B 506
DATA
50, z, 6
6507
DATA
20, z, 7.
B50B
DATA
30, z, z
8509
DATA
100, Zt z
0510
DATA
-1, 07, z
8511
DATA
-i, no, z
8512
DATA
-1, 200, z
8513
DATA
-1, 200, Z
9514
DATA
10, z * z
8515
DATA
Zf Z| *
0516
DATA
2, Z, Z
8517
DATA
z, z, fa-c5
851B
DATA
8519
DATA
Z, Z, Z
8520
DATA
2 , z, -fa-c s
B521
DATA
z, z,
B522
DATA
z , z , fa-cs
B523
DATA
z f z, fa-cs
8524
DATA
z, z, fa-cs
9525
DATA
z, z, fa-cs
9001
DATA
"in.the.living^room.of.a.large
*hause. *A *si gn *say5 ^Return *al 1
i treci5ures i here,% 2, z, z, z, z , 12* z
7002
DATA
" i n tchen'% z, 1, 3, z, z, z, z f
z
9003
DATA
eS, z, 4, 5, 2, z, z, z
9004
DATA
ef, 3, 7, 6, z, z, z, z
7005
DATA
e*, z, 6, 7, 3, z, z, z
9006
DATA
st, 5, 8, z, 4, z, z, z
9007
DATA
et, z, z, z, 4q z, z, z
900B
DATA
e$, 6, 9, z, z, z, z, z
9009
DATA
, B, z, 10, z, z, z, z
9010
DATA
ef, 11, z, z, 9, z, z, z
9011
DATA
"at.an.oasis", z, lO, z, z, z, z, z
9012
DATA
“in.a.celUr", z, 16, 13, z, 1, z, 1
9013
DATA
i5ata
"at.the* fcftT £Hi 2GATES^OF ^HELL EXT
12, z, 20, z
5HI
9014
"in.a. 1N v blackened.cavern TRU ", z.
15,
z*
9015
DATA
p*, 14, 18, z, 16, z, 2 , z
9016
DATA
p*, 12, z, 15, z, z, 17, z
7017
data
"in.the.pirates.lair", z, z, z, z, 16,
50
9018
DATA
15, 19, z, z, z, z, z
9019
DATA
p *, 10, z s z, z, z, z, z
9020
DATA
“in *HELL. - , ^A^devi] .says.’Find ..the?
4 r»ght ^direction *and . *1 i ve*- 4 T SHI 2e]
.die £XT SfcLI O'", -30, 30, 30, 21, 30, 30
, 2
9021
DATA
p*, z, 24, 22, 20, z, z, z
9022
DATA
"in.a.dead..and“, z, z, z, 21, z, z ? z
9023
DATA
11 ELSJt 0 EXT mi 2DEAD* IN.HELL EXT 7
£2i.I
Zj
z, z, z
9024
DATA
"at.the.brink.Df.a.deep* *chasm", 21,
25,
, z, z, z, z, z
<7025 DATA " i n A a *beaut i f ul * jfcwel 1 ed *hal 1 % 24 f z,
27i Zi zj z , 3
9026 DATA "at *tbe A br i n k +o-f *deep * *pi t. *Ther e
^are^traces^* EL3JI £±±i 2fire EXT SH I O^^and
* &Z2E 6brimstone £J±I Z^here.* 1 , 2* 27, z, z, 2, 23,
z
9027 DATA pfc, 26, z, r, 25, z m 28, z
9028 DATA p*, z, z, z, z, 27, 18, 2
9029 DATA " EXT Sjjj Iswi mming A in A a *smal 1 *1 ake EXT SHI 0 ",
z, z, z, z, z f z, 4
9030 DATA 11M , z, 2 , z, z, z, 2 , 60
99BO PRINT * PRINT 5 PRINT ; PRINT
9981 PRINT ” CONGRA TUL AT IONS * * * Th i 5 * adven t urei s
4 over ^and ^you ave^returned iJllJL safeI y
j.wi th ^al 1 *the^treasures* fl
9990 PRINT i PRINT "SCORE j. *' ; sc ± PRINT M Do*you
*wish*to*play^aqat n^7"
999] LET m* = INKEY* * IF mt = "" THEN BO TO 9991
9992 IF ro${ TO 1) = H y" THEN 60 TO 5
4
164
HINTS FOR PLAYING THE ADVENTURE PROGRAM
Hints for playing the ADVENTURE program
(1) Lost in the desert?
Do not despair the desert is not really endless
and if you strategically drop objects in the desert you
should be able to make a map of the desert. You will
need this map to find the oasis.
(2) Can't get through the living room door?
You will need the key that Is buried somewhere in
the desert. To dig up the key you will of course need a
shovel which is also outside the house — somewhere.
(3) Stuck in HELL?
Do what the devil says.
(4) Can't get past the pirate?
Try the rum.
(5) Can't kill the dragon?
Keep trying.
(6) Can't find the key to the gate?
Try the rope.
(7) Can't cross the chasm?
Maybe a magic wand would be of assistance.
(8) Can't find the last treasure?
Go swimming.
ANNOUNCING
I pud i rug aurhtinly on
In ihi* bank H* givrt a tofnplfl*
ovvrvipw of ih# way Speclrum
tfwralu, kerb far BASIC and mathim*
I gng u ogi prag re mm i ag A tprcial
on Th« ROM ope mi-lug lyilvrn,
will givr you- inn^ht into rfin rompijifr
□1 wt!i Di provide yog wilh anfarmatton
or haw iq ui* mgny ®f the routines
preioni m ike ROM THu book an.a muif
if you are lenaul nbour prD^iornmmg
111* ip#rlmm Only £? 05
yvffin* >p»flrgm mil# COOK wh#f*
wifi find your drppmt r#ally tfgrgmr
lru*. If you wont lo know how Po uh
ike EomplePe facHily of the Spetfrum
ei well os ho** the full hiring fat over
30 5p*c< ru m prog re rm, Phil it I He book
for you FnnlQitrE programs iuth ci Ihe
mrrrcfibl# JO-Marrmun Afirn frivadWi
|uH lenriniunlwg Cornu uldike*
educDtronel and butmtii pregraim
are ell m Over the SpecP-r-um Orly Eb VS
Thai titEo^pookf for iriolf if s everything
you need Po understand abaur Spec i rum
Modune language whan you're |u*l
uforP i ng off Am uit fat o 11 now Spot Prom
owners Orly £* V5
After leading the way in Sinclair 2X81 software, we've
produced the highest quality, most exciting Spectrum
software available, From the three excellent boohs
depicted above to fost-oction gomes on cassette,
we re providing the best choice in Sinclair Spectrum
software today
Whether jt‘i far your new Spectrum or ZX8I
Melbourne House has books and programs perfectly
suited to your needs.
Send far your Spectrum or ZX01 catalogue today.
IwS MELBOURNE
HOUSE
PUBLISHERS
I'.K. Melbourne 1 House (Publishers) Ltd.,
Glebe lottdgt 1 * Glebe House* Station Road,
Che dd trig ton, Leighton Buzzard, BEDS LU7 7NA
t). S, A. : Melbourne House Software Inc.,
347 Reedwood Drive, Nashville IN 37217.
Australia fit New Zealand:
Melbourne House (Australia) Pty Ltd,
Suite 4/7 5 P;jl mens ton Crescent,
Sth. Melbourne 3205,
Not a teach-yourself-programming guide, it is a collection of
programs: each program has a detailed breakdown of exactly what
happens when and how ifs all achieved.
The listings are not trivial, and the result is well worth the effort.
The book is liberally illustrated in colour showing screen displays for
almost all the programs so you know what you are trying to achieve
at the outset.
As a demonstration of what can be achieved using the Spectrum's
User Defined Characters this book cannot be faulted, and although it
contains no programming hints as such, a diligent reader is going to
learn a lot about the Spectrum by working his or her way through it.
Take a bow gents, and give us more."
PERSONAL COMPUTER WORLL
Melbourne House Publishers
"Final entrant in the Spectrum stakes is Melbourne House's OVER THE
SPECTRUM, and for me it runs out the clear winner.
A